**************************************************************************************************************************************************
****************************** Wealth-Income Ratios in Free Market Capitalism: Switzerland, 1900-2020 ********************************************
**************************************************************************************************************************************************
clear all
set more off
set scheme s1color  

**Author: Enea Baselgia and Isabel Z. Martinez
**Date: January, 25 2023

*** set this path to the current directory
*** global mypath "C:\Users\EBaselgia\Dropbox\WIR_project\Publication_process\replication"


*** THIS DO-FILE GENERATES ALL TABLES SHOWN IN THE PAPER AND IN THE ONLINE APPENDIX

**********************************************************************
***** Generate Table 1 
**********************************************************************

*** This generates the first part of results displayed in Table 1
***read data 
cd "$mypath/final_data/"
use "WIR_final.dta", clear
cd "$mypath/output/tables/"

*** geometric average growth rate of real national income 
*** 1995-2020
gen ch_gmean_gr_nni_1995_2020 = (ch_nni_T_R[121]/ch_nni_T_R[96])^(1/25) - 1

*** 1995-2002
gen ch_gmean_gr_nni_1995_2002 = (ch_nni_T_R[103]/ch_nni_T_R[96])^(1/7) - 1

*** 2002-2010
gen ch_gmean_gr_nni_2002_2010 = (ch_nni_T_R[111]/ch_nni_T_R[103])^(1/8) - 1

*** 2010-2020
gen ch_gmean_gr_nni_2010_2020 = (ch_nni_T_R[121]/ch_nni_T_R[111])^(1/10) - 1


*** geometric average growth rate of real per capita national income
*** 1995-2020
gen ch_gmean_gr_nni_PC_1995_2020 = (ch_nni_PC_R[121]/ch_nni_PC_R[96])^(1/25) - 1

*** 1995-2002
gen ch_gmean_gr_nni_PC_1995_2002 = (ch_nni_PC_R[103]/ch_nni_PC_R[96])^(1/7) - 1

*** 2002-2010
gen ch_gmean_gr_nni_PC_2002_2010 = (ch_nni_PC_R[111]/ch_nni_PC_R[103])^(1/8) - 1

*** 2010-2020
gen ch_gmean_gr_nni_PC_2010_2020 = (ch_nni_PC_R[121]/ch_nni_PC_R[111])^(1/10) - 1



*** geometric average growth rate of population
*** 1995-2020
gen ch_gmean_gr_pop_1995_2020 = (ch_pop_total[121]/ch_pop_total[96])^(1/25) - 1

*** 1995-2002
gen ch_gmean_gr_pop_1995_2002 = (ch_pop_total[103]/ch_pop_total[96])^(1/7) - 1

*** 2002-2010
gen ch_gmean_gr_pop_2002_2010 = (ch_pop_total[111]/ch_pop_total[103])^(1/8) - 1

*** 2010-2020
gen ch_gmean_gr_pop_2010_2020 = (ch_pop_total[121]/ch_pop_total[111])^(1/10) - 1




*** change in the nWIR in pp.
*** 1995-2020
gen ch_nWIR_delta_1995_2020 = ch_nWIR_T[121]-ch_nWIR_T[96]

*** 1995-2002
gen ch_nWIR_delta_1995_2002 = ch_nWIR_T[103]-ch_nWIR_T[96]

*** 2002-2010
gen ch_nWIR_delta_2002_2010 = ch_nWIR_T[111]-ch_nWIR_T[103]

*** 2010-2020
gen ch_nWIR_delta_2010_2020 = ch_nWIR_T[121]-ch_nWIR_T[111]



*** Net national savings rate weighted by national income for different time spans
gen ch_sum_saveR_nni = sum(ch_nni_T_R*ch_saveR_n) if year >1994
gen ch_sum_nni = sum(ch_nni_T_R) if year >1994
gen ch_sum_saveR_nni_2 = sum(ch_nni_T_R*ch_saveR_n) if year >2001
gen ch_sum_nni_2 = sum(ch_nni_T_R) if year >2001
gen ch_sum_saveR_nni_3 = sum(ch_nni_T_R*ch_saveR_n) if year >2009
gen ch_sum_nni_3 = sum(ch_nni_T_R) if year >2009

***
*** 1995-2020
gen ch_saveR_n_1995_2020 = ch_sum_saveR_nni[121]/ch_sum_nni[121]

*** 1995-2002
gen ch_saveR_n_1995_2002 = ch_sum_saveR_nni[103]/ch_sum_nni[103]

*** 2002-2010
gen ch_saveR_n_2002_2010 = ch_sum_saveR_nni_2[111]/ch_sum_nni_2[111]

*** 2010-2020
gen ch_saveR_n_2010_2020 = ch_sum_saveR_nni_3[121]/ch_sum_nni_3[121]



*** export
keep year ch_gmean_gr_nni_1995_2020 ch_gmean_gr_nni_1995_2002 ch_gmean_gr_nni_2002_2010 ch_gmean_gr_nni_2010_2020 ch_gmean_gr_nni_PC_1995_2020 ch_gmean_gr_nni_PC_1995_2002 ch_gmean_gr_nni_PC_2002_2010 ch_gmean_gr_nni_PC_2010_2020 ch_gmean_gr_pop_1995_2020 ch_gmean_gr_pop_1995_2002 ch_gmean_gr_pop_2002_2010 ch_gmean_gr_pop_2010_2020 ch_nWIR_delta_1995_2020 ch_nWIR_delta_1995_2002 ch_nWIR_delta_2002_2010 ch_nWIR_delta_2010_2020 ch_saveR_n_1995_2020 ch_saveR_n_1995_2002 ch_saveR_n_2002_2010 ch_saveR_n_2010_2020
drop if year != 2020
drop year
export excel using "Tab_1a.xls", firstrow(variables)  replace




***read data 
cd "$mypath/final_data/"
use "WIR_final.dta", clear
cd "$mypath/output/tables/"

*** This generates the second part of results displayed in Table 1

*** nWIR
gen ch_nWIR_1995 = ch_nWIR_T[96]
gen ch_nWIR_2002 = ch_nWIR_T[103]
gen ch_nWIR_2010 = ch_nWIR_T[111]
gen ch_nWIR_2020 = ch_nWIR_T[121]

*** growth rate of real national wealth
gen ch_nW_gr_T_R = ch_nW_T_R / ch_nW_T_R[_n-1]
gen ch_nW_gr_T_R_2 = (ch_nWIR_T/ch_nWIR_T[_n-1])*(1+ch_nni_gr_T_R)

*** savings indueced wealth grwoth rate
gen ch_gwst = ch_saveR_n[_n-1] / ch_nWIR_T[_n-1] +1


*** capital-gains-indueced wealth growth rate
gen ch_qt = (ch_nW_gr_T_R)/(ch_gwst)



***1995-2020
gen ch_nW_gr_1995_2020_1 = (ch_nW_T_R[121]/ch_nW_T_R[96])^(1/25) -1
egen ch_nW_gr1_1995_2020 = prod(ch_nW_gr_T_R) if year>=1996 & year<=2020
gen ch_nW_gr_1995_2020 = (ch_nW_gr1_1995_2020)^(1/25) -1
gen dif_test = ch_nW_gr_1995_2020_1 - ch_nW_gr_1995_2020
drop dif_test

egen ch_gwst_gr1_1995_2020 = prod(ch_gwst) if year>=1996 & year<=2020
gen ch_gwst_gr_1995_2020 = (ch_gwst_gr1_1995_2020)^(1/25) -1
egen ch_qt_gr1_1995_2020 = prod(ch_qt) if year>=1996 & year<=2020
gen ch_qt_gr_1995_2020 = (ch_qt_gr1_1995_2020)^(1/25) -1
gen ch_dif_test = ch_nW_gr_1995_2020 - ch_gwst_gr_1995_2020 - ch_qt_gr_1995_2020
drop ch_dif_test


***1995-2002
gen ch_nW_gr_1995_2002_1 = (ch_nW_T_R[103]/ch_nW_T_R[96])^(1/7) -1
egen ch_nW_gr1_1995_2002 = prod(ch_nW_gr_T_R) if year>=1996 & year<=2002
gen ch_nW_gr_1995_2002 = (ch_nW_gr1_1995_2002)^(1/7) -1
gen dif_test = ch_nW_gr_1995_2002_1 - ch_nW_gr_1995_2002
drop dif_test

egen ch_gwst_gr1_1995_2002 = prod(ch_gwst) if year>=1996 & year<=2002
gen ch_gwst_gr_1995_2002 = (ch_gwst_gr1_1995_2002)^(1/7) -1
egen ch_qt_gr1_1995_2002 = prod(ch_qt) if year>=1996 & year<=2002
gen ch_qt_gr_1995_2002 = (ch_qt_gr1_1995_2002)^(1/7) -1
gen ch_dif2 = ch_nW_gr_1995_2002 - ch_gwst_gr_1995_2002 - ch_qt_gr_1995_2002
drop ch_dif2


***2002-2010
gen ch_nW_gr_2002_2010_1 = (ch_nW_T_R[111]/ch_nW_T_R[103])^(1/8) -1
egen ch_nW_gr1_2002_2010 = prod(ch_nW_gr_T_R) if year>=2003 & year<=2010
gen ch_nW_gr_2002_2010 = (ch_nW_gr1_2002_2010)^(1/8) -1
gen dif_test = ch_nW_gr_2002_2010_1 - ch_nW_gr_2002_2010
drop dif_test

egen ch_gwst_gr1_2002_2010 = prod(ch_gwst) if year>=2003 & year<=2010
gen ch_gwst_gr_2002_2010 = (ch_gwst_gr1_2002_2010)^(1/8) -1
egen ch_qt_gr1_2002_2010 = prod(ch_qt) if year>=2003 & year<=2010
gen ch_qt_gr_2002_2010 = (ch_qt_gr1_2002_2010)^(1/8) -1
gen ch_dif3 = ch_nW_gr_2002_2010 - ch_gwst_gr_2002_2010 - ch_qt_gr_2002_2010
drop ch_dif3


***2010-2020
egen ch_nW_gr1_2010_2020 = prod(ch_nW_gr_T_R) if year>=2011 & year<=2020
gen ch_nW_gr_2010_2020 = (ch_nW_gr1_2010_2020)^(1/10) -1
egen ch_gwst_gr1_2010_2020 = prod(ch_gwst) if year>=2011 & year<=2020
gen ch_gwst_gr_2010_2020 = (ch_gwst_gr1_2010_2020)^(1/10) -1
egen ch_qt_gr1_2010_2020 = prod(ch_qt) if year>=2011 & year<=2020
gen ch_qt_gr_2010_2020 = (ch_qt_gr1_2010_2020)^(1/10) -1
gen ch_dif4 = ch_nW_gr_2010_2020 - ch_gwst_gr_2010_2020 - ch_qt_gr_2010_2020
drop ch_dif4


*** Export
keep year ch_nWIR_1995 ch_nWIR_2002 ch_nWIR_2010 ch_nWIR_2020 ch_nW_gr_1995_2020 ch_gwst_gr_1995_2020 ch_qt_gr_1995_2020 ch_nW_gr_1995_2002 ch_gwst_gr_1995_2002 ch_qt_gr_1995_2002 ch_nW_gr_2002_2010 ch_gwst_gr_2002_2010 ch_qt_gr_2002_2010 ch_nW_gr_2010_2020 ch_gwst_gr_2010_2020 ch_qt_gr_2010_2020
replace ch_nW_gr_2010_2020 = ch_nW_gr_2010_2020[121]
replace ch_gwst_gr_2010_2020 = ch_gwst_gr_2010_2020[121] 
replace ch_qt_gr_2010_2020 = ch_qt_gr_2010_2020[121] 
replace ch_nW_gr_2002_2010 = ch_nW_gr_2002_2010[108]
replace ch_gwst_gr_2002_2010 = ch_gwst_gr_2002_2010[108] 
replace ch_qt_gr_2002_2010 = ch_qt_gr_2002_2010[108] 
drop if year != 2000
drop year
export excel using "Tab_1b.xls", firstrow(variables) replace







**********************************************************************************
**************************** PrivateWIR Decomposition  ***************************
**************************** Housing vs Non-housing    ***************************
**********************************************************************************

**********************************************************************
***** Generate Table 2 
**********************************************************************

*** This generates the first part of results displayed in Table 1
***read data 
cd "$mypath/final_data/"
use "WIR_final.dta", clear
cd "$mypath/output/tables/"


***PrivateWIR Decomposition
*** pWIR
gen ch_pWIR_2000 = ch_pWIR[101]
gen ch_pWIR_2010 = ch_pWIR[111]
gen ch_pWIR_2020 = ch_pWIR[121]

*** growth rate of real private wealth
gen ch_pW_gr_T_R = ch_pW_T_R / ch_pW_T_R[_n-1]

*** savings indueced wealth grwoth rate
gen ch_p_gwst = ch_saveR_HH_nP[_n-1] / ch_pWIR[_n-1] +1

*** capital-gains-indueced wealth growth rate
gen ch_p_qt = (ch_pW_gr_T_R)/(ch_p_gwst)


***2000-2020
egen ch_pW_gr1_2000_2020 = prod(ch_pW_gr_T_R) if year>=2001 & year<=2020
gen ch_pW_gr_2000_2020 = (ch_pW_gr1_2000_2020)^(1/20) -1
egen ch_p_gwst_gr1_2000_2020 = prod(ch_p_gwst) if year>=2001 & year<=2020
gen ch_p_gwst_gr_2000_2020 = (ch_p_gwst_gr1_2000_2020)^(1/20) -1
egen ch_p_qt_gr1_2000_2020 = prod(ch_p_qt) if year>=2001 & year<=2020
gen ch_p_qt_gr_2000_2020 = (ch_p_qt_gr1_2000_2020)^(1/20) -1
gen ch_dif1 = ch_pW_gr_2000_2020 - ch_p_gwst_gr_2000_2020 - ch_p_qt_gr_2000_2020
drop ch_dif1

***2000-2010
egen ch_pW_gr1_2000_2010 = prod(ch_pW_gr_T_R) if year>=2001 & year<=2010
gen ch_pW_gr_2000_2010 = (ch_pW_gr1_2000_2010)^(1/10) -1
egen ch_p_gwst_gr1_2000_2010 = prod(ch_p_gwst) if year>=2001 & year<=2010
gen ch_p_gwst_gr_2000_2010 = (ch_p_gwst_gr1_2000_2010)^(1/10) -1
egen ch_p_qt_gr1_2000_2010 = prod(ch_p_qt) if year>=2001 & year<=2010
gen ch_p_qt_gr_2000_2010 = (ch_p_qt_gr1_2000_2010)^(1/10) -1
gen ch_dif2 = ch_pW_gr_2000_2010 - ch_p_gwst_gr_2000_2010 - ch_p_qt_gr_2000_2010
drop ch_dif2

***2010-2020
egen ch_pW_gr1_2010_2020 = prod(ch_pW_gr_T_R) if year>=2011 & year<=2020
gen ch_pW_gr_2010_2020 = (ch_pW_gr1_2010_2020)^(1/10) -1
egen ch_p_gwst_gr1_2010_2020 = prod(ch_p_gwst) if year>=2011 & year<=2020
gen ch_p_gwst_gr_2010_2020 = (ch_p_gwst_gr1_2010_2020)^(1/10) -1
egen ch_p_qt_gr1_2010_2020 = prod(ch_p_qt) if year>=2011 & year<=2020
gen ch_p_qt_gr_2010_2020 = (ch_p_qt_gr1_2010_2020)^(1/10) -1
gen ch_dif3 = ch_pW_gr_2010_2020 - ch_p_gwst_gr_2010_2020 - ch_p_qt_gr_2010_2020
drop ch_dif3





****nominal changens in net private wealth -- are used for further computations below
/// change in net private Wealth from year to year nominal
gen ch_pW_T_yearly_change = ch_pW_T - ch_pW_T[_n-1] if year >= 2000
/// savings indueced change in net private Wealth from year to year
gen ch_pW_save_yearly_change = ch_saveR_HH_nP * ch_nni_T if year >= 2000
/// capitalgains indueced change in net private Wealth from year to year / can be estimated as residual 
gen ch_pW_cpg_yearly_change = ch_pW_T_yearly_change - ch_pW_save_yearly_change




**************************************************************************************************
******************* Decomposition of Housing and non Housing Private Wealth***********************
**************************************************************************************************

**** Non-housing-Wealth*** --> Net Financial Wealth including Pension wealth

***Non-Housing-WIR 


gen ch_nonHouseWIR = (ch_pW_netfin_T+ch_pW_pension_T) / ch_nni_T

gen ch_nonHouseWIR_2000 = ch_nonHouseWIR[101]
gen ch_nonHouseWIR_2010 = ch_nonHouseWIR[111]
gen ch_nonHouseWIR_2020 = ch_nonHouseWIR[121]

*** growth rate of real non-housing wealth
gen ch_pW_nonHouse_T_R = ch_pW_netfin_total_T / ch_cpi
gen ch_pW_nonHouse_gr_T_R = ch_pW_nonHouse_T_R / ch_pW_nonHouse_T_R[_n-1]


*** savings rate of non-housing wealth 
/// from the financial accounts we have additional information on private non-housing Wealth (net financial wealth including pension wealth)
/// we know which part of change in the in non-housing Wealth can be attributed to savings "ch_pW_netfin_total_trans" 
/// capital gains "ch_pW_netfin_total_cp" and statistical changes/reclassifications "ch_pW_netfin_total_statchange"
/// statiscial change are of relevant magnitued and can not just somehow be split up between savings and capital gains 
/// we know however that the major part of statistical changes in non-housing wealth (including pension wealth) comes from reclassifications
/// regarding pension wealth "ch_pW_pension_statchange". These changes are done because considerable part of retirees move abroad and take their pension wealth with
/// them. For our analysis we thus can regard the as negative savings (as these are outflows) since we are intrested in the evolution of wealth of Swiss residents (inländerprinzip)
gen ch_pW_netfin_statchange_rest = ch_pW_netfin_total_statchange - ch_pW_pension_statchange
gen ch_pW_netfin_cpg_fin = ch_pW_netfin_total_cp + ch_pW_netfin_statchange_rest
/// we thus add "ch_pW_pension_statchange" to the savings component to account for the outflow of pension wealth 
/// the rest of statistical reclassifications "ch_pW_netfin_statchange_rest" is add to the capital gains component
gen ch_pW_netfin_save_fin = ch_pW_netfin_total_trans + ch_pW_pension_statchange
gen ch_saveR_nonHouse = ch_pW_netfin_save_fin / ch_nni_T

/// test to see if capital gains in nominal term are derived correctly
gen ch_test_cp = ch_pW_netfin_total_T - ch_pW_netfin_total_T[_n-1] - ch_pW_netfin_save_fin
gen ch_test_cp1 = ch_test_cp - ch_pW_netfin_cpg_fin
drop ch_test_cp ch_test_cp1

*** savings indueced wealth grwoth rate on non-housing wealth
gen ch_nonHouse_gwst = ch_saveR_nonHouse[_n-1] / ch_nonHouseWIR[_n-1] +1

*** capital-gains-indueced wealth growth rate
gen ch_nonHouse_qt = (ch_pW_nonHouse_gr_T_R)/(ch_nonHouse_gwst)



**** Housing-Wealth***
/// total nominal savings in housing are the difference of total household savings and savings in non-housing wealth
gen ch_pW_housing_save = ch_pW_save_yearly_change - ch_pW_netfin_save_fin

/// total nominal capital gains in housing are the difference of total household capital gains and capital gains in non-housing wealth
gen ch_pW_housing_cp = ch_pW_cpg_yearly_change - ch_pW_netfin_cpg_fin

/// change in nominal housing wealth 
gen ch_pW_housing_T_yearly_change = ch_pW_housing_cp + ch_pW_housing_save
gen housing_test = ch_pW_housing_T_yearly_change - (ch_pW_housing_T -ch_pW_housing_T[_n-1])
drop housing_test
/// note that by construction this changes "ch_pW_housing_T_yearly_change" coincidence to the year to year changes of the variable "ch_pW_housing_T"
/// based on the series "ch_pW_housing_T_yearly_change" we further can prolong the series "ch_pW_housing_T" on more period backward (useful to analysis the entire period since 2000)
replace ch_pW_housing_T = ch_pW_housing_T[101] - ch_pW_housing_T_yearly_change[101] if year==1999


***Housing-WIR 
gen ch_HouseWIR = ch_pW_housing_T / ch_nni_T

gen ch_HouseWIR_2000 = ch_HouseWIR[101]
gen ch_HouseWIR_2010 = ch_HouseWIR[111]
gen ch_HouseWIR_2020 = ch_HouseWIR[121]

*** growth rate of real non-housing wealth
drop ch_pW_housing_T_R
gen ch_pW_housing_T_R = ch_pW_housing_T / ch_cpi
gen ch_pW_housing_gr_T_R = ch_pW_housing_T_R / ch_pW_housing_T_R[_n-1]


*** savings indueced wealth grwoth rate on non-housing wealth
gen ch_saveR_housing = ch_pW_housing_save / ch_nni_T
gen ch_housing_gwst = ch_saveR_housing[_n-1] / ch_HouseWIR[_n-1] +1


*** capital-gains-indueced wealth growth rate
gen ch_housing_qt = (ch_pW_housing_gr_T_R)/(ch_housing_gwst)


********************* Non-Housing Decomposition *********************

***2000-2020
egen ch_NonhousW_gr1_2000_2020 = prod(ch_pW_nonHouse_gr_T_R) if year>=2001 & year<=2020
gen ch_NonhousW_gr_2000_2020 = (ch_NonhousW_gr1_2000_2020)^(1/20) -1
egen ch_NonhousW_gwst_gr1_2000_2020 = prod(ch_nonHouse_gwst) if year>=2001 & year<=2020
gen ch_NonhousW_gwst_gr_2000_2020 = (ch_NonhousW_gwst_gr1_2000_2020)^(1/20) -1
egen ch_NonhousW_qt_gr1_2000_2020 = prod(ch_nonHouse_qt) if year>=2001 & year<=2020
gen ch_NonhousW_qt_gr_2000_2020 = (ch_NonhousW_qt_gr1_2000_2020)^(1/20) -1
gen ch_dif1 = ch_NonhousW_gr_2000_2020 - ch_NonhousW_gwst_gr_2000_2020 - ch_NonhousW_qt_gr_2000_2020
drop ch_dif1


***2000-2010
egen ch_NonhousW_gr1_2000_2010 = prod(ch_pW_nonHouse_gr_T_R) if year>=2001 & year<=2010
gen ch_NonhousW_gr_2000_2010 = (ch_NonhousW_gr1_2000_2010)^(1/10) -1
egen ch_NonhousW_gwst_gr1_2000_2010 = prod(ch_nonHouse_gwst) if year>=2001 & year<=2010
gen ch_NonhousW_gwst_gr_2000_2010 = (ch_NonhousW_gwst_gr1_2000_2010)^(1/10) -1
egen ch_NonhousW_qt_gr1_2000_2010 = prod(ch_nonHouse_qt) if year>=2001 & year<=2010
gen ch_NonhousW_qt_gr_2000_2010 = (ch_NonhousW_qt_gr1_2000_2010)^(1/10) -1
gen ch_dif2 = ch_NonhousW_gr_2000_2010 - ch_NonhousW_gwst_gr_2000_2010 - ch_NonhousW_qt_gr_2000_2010
drop ch_dif2

***2010-2020
egen ch_NonhousW_gr1_2010_2020 = prod(ch_pW_nonHouse_gr_T_R) if year>=2011 & year<=2020
gen ch_NonhousW_gr_2010_2020 = (ch_NonhousW_gr1_2010_2020)^(1/10) -1
egen ch_NonhousW_gwst_gr1_2010_2020 = prod(ch_nonHouse_gwst) if year>=2011 & year<=2020
gen ch_NonhousW_gwst_gr_2010_2020 = (ch_NonhousW_gwst_gr1_2010_2020)^(1/10) -1
egen ch_NonhousW_qt_gr1_2010_2020 = prod(ch_nonHouse_qt) if year>=2011 & year<=2020
gen ch_NonhousW_qt_gr_2010_2020 = (ch_NonhousW_qt_gr1_2010_2020)^(1/10) -1
gen ch_dif3 = ch_NonhousW_gr_2010_2020 - ch_NonhousW_gwst_gr_2010_2020 - ch_NonhousW_qt_gr_2010_2020
drop ch_dif3




********************* Housing Decomposition *********************

***2000-2020
egen ch_housingW_gr1_2000_2020 = prod(ch_pW_housing_gr_T_R) if year>=2001 & year<=2020
gen ch_housingW_gr_2000_2020 = (ch_housingW_gr1_2000_2020)^(1/20) -1
egen ch_housing_gwst_gr1_2000_2020 = prod(ch_housing_gwst) if year>=2001 & year<=2020
gen ch_housing_gwst_gr_2000_2020 = (ch_housing_gwst_gr1_2000_2020)^(1/20) -1
egen ch_housing_qt_gr1_2000_2020 = prod(ch_housing_qt) if year>=2001 & year<=2020
gen ch_housing_qt_gr_2000_2020 = (ch_housing_qt_gr1_2000_2020)^(1/20) -1
gen ch_dif1 = ch_housingW_gr_2000_2020 - ch_housing_gwst_gr_2000_2020 - ch_housing_qt_gr_2000_2020
drop ch_dif1

***2000-2010
egen ch_housingW_gr1_2000_2010 = prod(ch_pW_housing_gr_T_R) if year>=2001 & year<=2010
gen ch_housingW_gr_2000_2010 = (ch_housingW_gr1_2000_2010)^(1/10) -1
egen ch_housing_gwst_gr1_2000_2010 = prod(ch_housing_gwst) if year>=2001 & year<=2010
gen ch_housing_gwst_gr_2000_2010 = (ch_housing_gwst_gr1_2000_2010)^(1/10) -1
egen ch_housing_qt_gr1_2000_2010 = prod(ch_housing_qt) if year>=2001 & year<=2010
gen ch_housing_qt_gr_2000_2010 = (ch_housing_qt_gr1_2000_2010)^(1/10) -1
gen ch_dif2 = ch_housingW_gr_2000_2010 - ch_housing_gwst_gr_2000_2010 - ch_housing_qt_gr_2000_2010
drop ch_dif2

***2010-2020
egen ch_housingW_gr1_2010_2020 = prod(ch_pW_housing_gr_T_R) if year>=2011 & year<=2020
gen ch_housingW_gr_2010_2020 = (ch_housingW_gr1_2010_2020)^(1/10) -1
egen ch_housing_gwst_gr1_2010_2020 = prod(ch_housing_gwst) if year>=2011 & year<=2020
gen ch_housing_gwst_gr_2010_2020 = (ch_housing_gwst_gr1_2010_2020)^(1/10) -1
egen ch_housing_qt_gr1_2010_2020 = prod(ch_housing_qt) if year>=2011 & year<=2020
gen ch_housing_qt_gr_2010_2020 = (ch_housing_qt_gr1_2010_2020)^(1/10) -1
gen ch_dif3 = ch_housingW_gr_2010_2020 - ch_housing_gwst_gr_2010_2020 - ch_housing_qt_gr_2010_2020
drop ch_dif3


*** Export
keep year ch_pWIR_2000 ch_pWIR_2010 ch_pWIR_2020 ch_pW_gr_2000_2020 ch_p_gwst_gr_2000_2020 ch_p_qt_gr_2000_2020 ch_pW_gr_2000_2010 ch_p_gwst_gr_2000_2010 ch_p_qt_gr_2000_2010 ch_pW_gr_2010_2020 ch_p_gwst_gr_2010_2020 ch_p_qt_gr_2010_2020 ch_HouseWIR_2000 ch_HouseWIR_2010 ch_HouseWIR_2020 ch_housingW_gr_2000_2020 ch_housing_gwst_gr_2000_2020 ch_housing_qt_gr_2000_2020 ch_housingW_gr_2000_2010 ch_housing_gwst_gr_2000_2010 ch_housing_qt_gr_2000_2010 ch_housingW_gr_2010_2020 ch_housing_gwst_gr_2010_2020 ch_housing_qt_gr_2010_2020 ch_nonHouseWIR_2000 ch_nonHouseWIR_2010 ch_nonHouseWIR_2020 ch_NonhousW_gr_2000_2020 ch_NonhousW_gwst_gr_2000_2020 ch_NonhousW_qt_gr_2000_2020 ch_NonhousW_gr_2000_2010 ch_NonhousW_gwst_gr_2000_2010 ch_NonhousW_qt_gr_2000_2010 ch_NonhousW_gr_2010_2020 ch_NonhousW_gwst_gr_2010_2020 ch_NonhousW_qt_gr_2010_2020

replace ch_pW_gr_2010_2020 = ch_pW_gr_2010_2020[121]
replace ch_p_gwst_gr_2010_2020 = ch_p_gwst_gr_2010_2020[121]
replace ch_p_qt_gr_2010_2020 = ch_p_qt_gr_2010_2020[121]
replace ch_housingW_gr_2010_2020 = ch_housingW_gr_2010_2020[121]
replace ch_housing_gwst_gr_2010_2020 = ch_housing_gwst_gr_2010_2020[121]
replace ch_housing_qt_gr_2010_2020 = ch_housing_qt_gr_2010_2020[121]
replace ch_NonhousW_gr_2010_2020 = ch_NonhousW_gr_2010_2020[121]
replace ch_NonhousW_gwst_gr_2010_2020 = ch_NonhousW_gwst_gr_2010_2020[121]
replace ch_NonhousW_qt_gr_2010_2020 = ch_NonhousW_qt_gr_2010_2020[121]
drop if year != 2010
drop year
export excel using "Tab_2.xls", firstrow(variables) replace




*********************************************************************
***** Generate Table B1
*********************************************************************
***read data 
cd "$mypath/final_data/"
use "WIR_final.dta", clear
cd "$mypath/output/tables/"

*** Net national savings rate weighted by national income for different time spans
gen ch_sum_saveR_nni = sum(ch_nni_T_R*ch_saveR_n) if year >1994
gen ch_sum_nni = sum(ch_nni_T_R) if year >1994
gen ch_sum_saveR_nni_2 = sum(ch_nni_T_R*ch_saveR_n) if year >2001
gen ch_sum_nni_2 = sum(ch_nni_T_R) if year >2001
gen ch_sum_saveR_nni_3 = sum(ch_nni_T_R*ch_saveR_n) if year >2009
gen ch_sum_nni_3 = sum(ch_nni_T_R) if year >2009

***
*** 1995-2020
gen ch_saveR_n_1995_2020 = ch_sum_saveR_nni[121]/ch_sum_nni[121]

*** 1995-2002
gen ch_saveR_n_1995_2002 = ch_sum_saveR_nni[103]/ch_sum_nni[103]

*** 2002-2010
gen ch_saveR_n_2002_2010 = ch_sum_saveR_nni_2[111]/ch_sum_nni_2[111]

*** 2010-2020
gen ch_saveR_n_2010_2020 = ch_sum_saveR_nni_3[121]/ch_sum_nni_3[121]


*** Net private savings rate weighted by national income for different time spans
gen ch_sum_saveR_p_nni = sum(ch_nni_T_R*ch_saveR_p) if year >1994
gen ch_sum_saveR_p_nni_2 = sum(ch_nni_T_R*ch_saveR_p) if year >2001
gen ch_sum_saveR_p_nni_3 = sum(ch_nni_T_R*ch_saveR_p) if year >2009

***
*** 1995-2020
gen ch_saveR_p_1995_2020 = ch_sum_saveR_p_nni[121]/ch_sum_nni[121]

*** 1995-2002
gen ch_saveR_p_1995_2002 = ch_sum_saveR_p_nni[103]/ch_sum_nni[103]

*** 2002-2010
gen ch_saveR_p_2002_2010 = ch_sum_saveR_p_nni_2[111]/ch_sum_nni_2[111]

*** 2010-2020
gen ch_saveR_p_2010_2020 = ch_sum_saveR_p_nni_3[121]/ch_sum_nni_3[121]


*** Net household savings rate weighted by national income for different time spans: 
gen ch_sum_saveR_HH_nni = sum(ch_nni_T_R*ch_saveR_HH_nP) if year >1994
gen ch_sum_saveR_HH_nni_2 = sum(ch_nni_T_R*ch_saveR_HH_nP) if year >2001
gen ch_sum_saveR_HH_nni_3 = sum(ch_nni_T_R*ch_saveR_HH_nP) if year >2009

***
*** 1995-2020
gen ch_saveR_HH_nP_1995_2020 = ch_sum_saveR_HH_nni[121]/ch_sum_nni[121]

*** 1995-2002
gen ch_saveR_HH_nP_1995_2002 = ch_sum_saveR_HH_nni[103]/ch_sum_nni[103]

*** 2002-2010
gen ch_saveR_HH_nP_2002_2010 = ch_sum_saveR_HH_nni_2[111]/ch_sum_nni_2[111]

*** 2010-2020
gen ch_saveR_HH_nP_2010_2020 = ch_sum_saveR_HH_nni_3[121]/ch_sum_nni_3[121]



*** Net corporate savings rate weighted by national income for different time spans
gen ch_sum_saveR_corp_nni = sum(ch_nni_T_R*ch_saveR_corp) if year >1994
gen ch_sum_saveR_corp_nni_2 = sum(ch_nni_T_R*ch_saveR_corp) if year >2001
gen ch_sum_saveR_corp_nni_3 = sum(ch_nni_T_R*ch_saveR_corp) if year >2009

***
*** 1995-2020
gen ch_saveR_corp_1995_2020 = ch_sum_saveR_corp_nni[121]/ch_sum_nni[121]

*** 1995-2002
gen ch_saveR_corp_1995_2002 = ch_sum_saveR_corp_nni[103]/ch_sum_nni[103]

*** 2002-2010
gen ch_saveR_corp_2002_2010 = ch_sum_saveR_corp_nni_2[111]/ch_sum_nni_2[111]

*** 2010-2020
gen ch_saveR_corp_2010_2020 = ch_sum_saveR_corp_nni_3[121]/ch_sum_nni_3[121]


*** Net public savings rate weighted by national income for different time spans: CH1995-2015; DE1995-2013; FR1995-2010; IT1995-2014; SE1995-2015; US1995-2013
*** Switzerland
gen ch_sum_saveR_g_nni = sum(ch_nni_T_R*ch_saveR_g) if year >1994
gen ch_sum_saveR_g_nni_2 = sum(ch_nni_T_R*ch_saveR_g) if year >2001
gen ch_sum_saveR_g_nni_3 = sum(ch_nni_T_R*ch_saveR_g) if year >2009

***
*** 1995-2020
gen ch_saveR_g_1995_2020 = ch_sum_saveR_g_nni[121]/ch_sum_nni[121]

*** 1995-2002
gen ch_saveR_g_1995_2002 = ch_sum_saveR_g_nni[103]/ch_sum_nni[103]

*** 2002-2010
gen ch_saveR_g_2002_2010 = ch_sum_saveR_g_nni_2[111]/ch_sum_nni_2[111]

*** 2010-2020
gen ch_saveR_g_2010_2020 = ch_sum_saveR_g_nni_3[121]/ch_sum_nni_3[121]


*** Export
keep year ch_saveR_n_1995_2020 ch_saveR_n_1995_2002 ch_saveR_n_2002_2010 ch_saveR_n_2010_2020 ch_saveR_p_1995_2020 ch_saveR_p_1995_2002 ch_saveR_p_2002_2010 ch_saveR_p_2010_2020 ch_saveR_HH_nP_1995_2020 ch_saveR_HH_nP_1995_2002 ch_saveR_HH_nP_2002_2010 ch_saveR_HH_nP_2010_2020 ch_saveR_corp_1995_2020 ch_saveR_corp_1995_2002 ch_saveR_corp_2002_2010 ch_saveR_corp_2010_2020 ch_saveR_g_1995_2020 ch_saveR_g_1995_2002 ch_saveR_g_2002_2010 ch_saveR_g_2010_2020
drop if year != 2020
drop year
export excel using "Tab_append_B_1.xls", firstrow(variables) replace



*********************************************************************
***** Generate Table B2
*********************************************************************
***read data 
cd "$mypath/final_data/"
use "WIR_final.dta", clear
cd "$mypath/output/tables/"

*********************************************************************
***** Structure of National Savings 1995-2018 *****
*********************************************************************

****Switzerland, 1995-2018*****

*** Net national savings rate weighted by national
gen ch_sum_saveR_nni = sum(ch_nni_T_R*ch_saveR_n) if year >1994
gen ch_sum_nni = sum(ch_nni_T_R) if year >1994
gen ch_saveR_n_1995_2018 = ch_sum_saveR_nni[119]/ch_sum_nni[119]

*** Net private savings rate weighted by national income
gen ch_sum_saveR_p_nni = sum(ch_nni_T_R*ch_saveR_p) if year >1994
gen ch_saveR_p_1995_2018 = ch_sum_saveR_p_nni[119]/ch_sum_nni[119]

*** Net household savings rate weighted by national income
gen ch_sum_saveR_HH_nni = sum(ch_nni_T_R*ch_saveR_HH_nP) if year >1994
gen ch_saveR_HH_nP_1995_2018 = ch_sum_saveR_HH_nni[119]/ch_sum_nni[119]

*** Net corporate savings rate weighted by national income
gen ch_sum_saveR_corp_nni = sum(ch_nni_T_R*ch_saveR_corp) if year >1994
gen ch_saveR_corp_1995_2018 = ch_sum_saveR_corp_nni[119]/ch_sum_nni[119]

*** Net public savings rate weighted by national income
gen ch_sum_saveR_g_nni = sum(ch_nni_T_R*ch_saveR_g) if year >1994
gen ch_saveR_g_1995_2018 = ch_sum_saveR_g_nni[119]/ch_sum_nni[119]

br year ch_saveR_p_1995_2018 ch_saveR_HH_nP_1995_2018 ch_saveR_corp_1995_2018 ch_saveR_g_1995_2018 ch_saveR_n_1995_2018



****Germany, 1995-2018*****
*** Net national savings rate weighted by national
gen de_sum_saveR_nni = sum(DE_nni_T_R*DE_saveR_n) if year >1994
gen de_sum_nni = sum(DE_nni_T_R) if year >1994
gen de_saveR_n_1995_2018 = de_sum_saveR_nni[119]/de_sum_nni[119]

*** Net private savings rate weighted by national income
gen de_sum_saveR_p_nni = sum(DE_nni_T_R*DE_saveR_p) if year >1994
gen de_saveR_p_1995_2018 = de_sum_saveR_p_nni[119]/de_sum_nni[119]

*** Net household savings rate weighted by national income
gen de_sum_saveR_HH_nni = sum(DE_nni_T_R*DE_saveR_HH_nP) if year >1994
gen de_saveR_HH_1995_2018 = de_sum_saveR_HH_nni[119]/de_sum_nni[119]

*** Net corporate savings rate weighted by national income
gen de_sum_saveR_corp_nni = sum(DE_nni_T_R*DE_saveR_corp) if year >1994
gen de_saveR_corp_1995_2018 = de_sum_saveR_corp_nni[119]/de_sum_nni[119]

*** Net public savings rate weighted by national income
gen de_sum_saveR_g_nni = sum(DE_nni_T_R*DE_saveR_g) if year >1994
gen de_saveR_g_1995_2018 = de_sum_saveR_g_nni[119]/de_sum_nni[119]

br year de_saveR_p_1995_2018 de_saveR_HH_1995_2018 de_saveR_corp_1995_2018 de_saveR_g_1995_2018 de_saveR_n_1995_2018




****France, 1995-2018*****
*** Net national savings rate weighted by national
gen fr_sum_saveR_nni = sum(FR_nni_T_R*FR_saveR_n) if year >1994
gen fr_sum_nni = sum(FR_nni_T_R) if year >1994
gen fr_saveR_n_1995_2018 = fr_sum_saveR_nni[119]/fr_sum_nni[119]

*** Net private savings rate weighted by national income
gen fr_sum_saveR_p_nni = sum(FR_nni_T_R*FR_saveR_p) if year >1994
gen fr_saveR_p_1995_2018 = fr_sum_saveR_p_nni[119]/fr_sum_nni[119]

*** Net household savings rate weighted by national income
gen fr_sum_saveR_HH_nni = sum(FR_nni_T_R*FR_saveR_HH_nP) if year >1994
gen fr_saveR_HH_1995_2018 = fr_sum_saveR_HH_nni[119]/fr_sum_nni[119]

*** Net corporate savings rate weighted by national income
gen fr_sum_saveR_corp_nni = sum(FR_nni_T_R*FR_saveR_corp) if year >1994
gen fr_saveR_corp_1995_2018 = fr_sum_saveR_corp_nni[119]/fr_sum_nni[119]

*** Net public savings rate weighted by national income
gen fr_sum_saveR_g_nni = sum(FR_nni_T_R*FR_saveR_g) if year >1994
gen fr_saveR_g_1995_2018 = fr_sum_saveR_g_nni[119]/fr_sum_nni[119]




****Italy, 1995-2018*****
*** Net national savings rate weighted by national
gen it_sum_saveR_nni = sum(IT_nni_T_R*IT_saveR_n) if year >1994
gen it_sum_nni = sum(IT_nni_T_R) if year >1994
gen it_saveR_n_1995_2018 = it_sum_saveR_nni[119]/it_sum_nni[119]

*** Net private savings rate weighted by national income
gen it_sum_saveR_p_nni = sum(IT_nni_T_R*IT_saveR_p) if year >1994
gen it_saveR_p_1995_2018 = it_sum_saveR_p_nni[119]/it_sum_nni[119]

*** Net household savings rate weighted by national income
gen it_sum_saveR_HH_nni = sum(IT_nni_T_R*IT_saveR_HH_nP) if year >1994
gen it_saveR_HH_1995_2018 = it_sum_saveR_HH_nni[119]/it_sum_nni[119]

*** Net corporate savings rate weighted by national income
gen it_sum_saveR_corp_nni = sum(IT_nni_T_R*IT_saveR_corp) if year >1994
gen it_saveR_corp_1995_2018 = it_sum_saveR_corp_nni[119]/it_sum_nni[119]

*** Net public savings rate weighted by national income
gen it_sum_saveR_g_nni = sum(IT_nni_T_R*IT_saveR_g) if year >1994
gen it_saveR_g_1995_2018 = it_sum_saveR_g_nni[119]/it_sum_nni[119]



****Sweden, 1995-2018*****
*** Net national savings rate weighted by national
gen se_sum_saveR_nni = sum(SE_nni_T_R*SE_saveR_n) if year >1994
gen se_sum_nni = sum(SE_nni_T_R) if year >1994
gen se_saveR_n_1995_2018 = se_sum_saveR_nni[119]/se_sum_nni[119]

*** Net private savings rate weighted by national income
gen se_sum_saveR_p_nni = sum(SE_nni_T_R*SE_saveR_p) if year >1994
gen se_saveR_p_1995_2018 = se_sum_saveR_p_nni[119]/se_sum_nni[119]

*** Net household savings rate weighted by national income
gen se_sum_saveR_HH_nni = sum(SE_nni_T_R*SE_saveR_HH_nP) if year >1994
gen se_saveR_HH_1995_2018 = se_sum_saveR_HH_nni[119]/se_sum_nni[119]

*** Net corporate savings rate weighted by national income
gen se_sum_saveR_corp_nni = sum(SE_nni_T_R*SE_saveR_corp) if year >1994
gen se_saveR_corp_1995_2018 = se_sum_saveR_corp_nni[119]/se_sum_nni[119]

*** Net public savings rate weighted by national income
gen se_sum_saveR_g_nni = sum(SE_nni_T_R*SE_saveR_g) if year >1994
gen se_saveR_g_1995_2018 = se_sum_saveR_g_nni[119]/se_sum_nni[119]



****United States, 1995-2018*****
*** Net national savings rate weighted by national
gen us_sum_saveR_nni = sum(US_nni_T_R*US_saveR_n) if year >1994
gen us_sum_nni = sum(US_nni_T_R) if year >1994
gen us_saveR_n_1995_2018 = us_sum_saveR_nni[119]/us_sum_nni[119]

*** Net private savings rate weighted by national income
gen us_sum_saveR_p_nni = sum(US_nni_T_R*US_saveR_p) if year >1994
gen us_saveR_p_1995_2018 = us_sum_saveR_p_nni[119]/us_sum_nni[119]

*** Net household savings rate weighted by national income
gen us_sum_saveR_HH_nni = sum(US_nni_T_R*US_saveR_HH_nP) if year >1994
gen us_saveR_HH_1995_2018 = us_sum_saveR_HH_nni[119]/us_sum_nni[119]

*** Net corporate savings rate weighted by national income
gen us_sum_saveR_corp_nni = sum(US_nni_T_R*US_saveR_corp) if year >1994
gen us_saveR_corp_1995_2018 = us_sum_saveR_corp_nni[119]/us_sum_nni[119]

*** Net public savings rate weighted by national income
gen us_sum_saveR_g_nni = sum(US_nni_T_R*US_saveR_g) if year >1994
gen us_saveR_g_1995_2018 = us_sum_saveR_g_nni[119]/us_sum_nni[119]

*** Export
keep year ch_saveR_p_1995_2018 ch_saveR_HH_nP_1995_2018 ch_saveR_corp_1995_2018 ch_saveR_g_1995_2018 ch_saveR_n_1995_2018 de_saveR_p_1995_2018 de_saveR_HH_1995_2018 de_saveR_corp_1995_2018 de_saveR_g_1995_2018 de_saveR_n_1995_2018 fr_saveR_p_1995_2018 fr_saveR_HH_1995_2018 fr_saveR_corp_1995_2018 fr_saveR_g_1995_2018 fr_saveR_n_1995_2018 it_saveR_p_1995_2018 it_saveR_HH_1995_2018 it_saveR_corp_1995_2018 it_saveR_g_1995_2018 it_saveR_n_1995_2018 se_saveR_p_1995_2018 se_saveR_HH_1995_2018 se_saveR_corp_1995_2018 se_saveR_g_1995_2018 se_saveR_n_1995_2018 us_saveR_p_1995_2018 us_saveR_HH_1995_2018 us_saveR_corp_1995_2018 us_saveR_g_1995_2018 us_saveR_n_1995_2018
drop if year != 2018
drop year
export excel using "Tab_append_B_2.xls", firstrow(variables) replace






*********************************************************************
***** Generate Table B3
*********************************************************************

*********************************************************************
*************** Growth and Saving Rates 1995-2018 *******************
*********************************************************************
***read data 
cd "$mypath/final_data/"
use "WIR_final.dta", clear
cd "$mypath/output/tables/"



***** Switzerland *****
*** geometric average growth rate of real national income 
gen ch_gmean_gr_nni_1995_2018 = (ch_nni_T_R[119]/ch_nni_T_R[96])^(1/23) - 1

*** geometric average growth rate of real per capita national income
gen ch_gmean_gr_nni_PC_1995_2018 = (ch_nni_PC_R[119]/ch_nni_PC_R[96])^(1/23) - 1

*** geometric average growth rate of population
gen ch_gmean_gr_pop_1995_2018 = (ch_pop_total[119]/ch_pop_total[96])^(1/23) - 1

*** change in the nWIR in pp.
gen ch_nWIR_delta_1995_2018 = ch_nWIR_T[119]-ch_nWIR_T[96]

*** Net national savings rate weighted by national
gen ch_sum_saveR_nni = sum(ch_nni_T_R*ch_saveR_n) if year >1994
gen ch_sum_nni = sum(ch_nni_T_R) if year >1994
gen ch_saveR_n_1995_2018 = ch_sum_saveR_nni[119]/ch_sum_nni[119]


***** Germany *****
*** geometric average growth rate of real national income 
gen de_gmean_gr_nni_1995_2018 = (DE_nni_T_R[119]/DE_nni_T_R[96])^(1/23) - 1

*** geometric average growth rate of real per capita national income
gen de_gmean_gr_nni_PC_1995_2018 = (DE_nni_PC_R[119]/DE_nni_PC_R[96])^(1/23) - 1

*** geometric average growth rate of population
gen de_gmean_gr_pop_1995_2018 = (DE_pop_total[119]/DE_pop_total[96])^(1/23) - 1

*** change in the nWIR in pp.
gen de_nWIR_delta_1995_2018 = DE_nWIR_excl_domW_agriW[119]-DE_nWIR_excl_domW_agriW[96]

*** Net national savings rate weighted by national, 1995-2018*****
gen de_sum_saveR_nni = sum(DE_nni_T_R*DE_saveR_n) if year >1994
gen de_sum_nni = sum(DE_nni_T_R) if year >1994
gen de_saveR_n_1995_2018 = de_sum_saveR_nni[119]/de_sum_nni[119]


***** France *****
*** geometric average growth rate of real national income 
gen fr_gmean_gr_nni_1995_2018 = (FR_nni_T_R[119]/FR_nni_T_R[96])^(1/23) - 1

*** geometric average growth rate of real per capita national income
gen fr_gmean_gr_nni_PC_1995_2018 = (FR_nni_PC_R[119]/FR_nni_PC_R[96])^(1/23) - 1

*** geometric average growth rate of population
gen fr_gmean_gr_pop_1995_2018 = (FR_pop_total[119]/FR_pop_total[96])^(1/23) - 1

*** change in the nWIR in pp.
gen fr_nWIR_delta_1995_2018 = FR_nWIR_excl_domW_agriW[119]-FR_nWIR_excl_domW_agriW[96]

*** Net national savings rate weighted by national, 1995-2018*****
gen fr_sum_saveR_nni = sum(FR_nni_T_R*FR_saveR_n) if year >1994
gen fr_sum_nni = sum(FR_nni_T_R) if year >1994
gen fr_saveR_n_1995_2018 = fr_sum_saveR_nni[119]/fr_sum_nni[119]


***** Italy *****
*** geometric average growth rate of real national income 
gen it_gmean_gr_nni_1995_2018 = (IT_nni_T_R[119]/IT_nni_T_R[96])^(1/23) - 1

*** geometric average growth rate of real per capita national income
gen it_gmean_gr_nni_PC_1995_2018 = (IT_nni_PC_R[119]/IT_nni_PC_R[96])^(1/23) - 1

*** geometric average growth rate of population
gen it_gmean_gr_pop_1995_2018 = (IT_pop_total[119]/IT_pop_total[96])^(1/23) - 1

*** change in the nWIR in pp.
gen it_nWIR_delta_1995_2018 = IT_nWIR_excl_domW_agriW[119]-IT_nWIR_excl_domW_agriW[96]

*** Net national savings rate weighted by national, 1995-2018*****
gen it_sum_saveR_nni = sum(IT_nni_T_R*IT_saveR_n) if year >1994
gen it_sum_nni = sum(IT_nni_T_R) if year >1994
gen it_saveR_n_1995_2018 = it_sum_saveR_nni[119]/it_sum_nni[119]


***** Sweden *****
*** geometric average growth rate of real national income 
gen se_gmean_gr_nni_1995_2018 = (SE_nni_T_R[119]/SE_nni_T_R[96])^(1/23) - 1

*** geometric average growth rate of real per capita national income
gen se_gmean_gr_nni_PC_1995_2018 = (SE_nni_PC_R[119]/SE_nni_PC_R[96])^(1/23) - 1

*** geometric average growth rate of population
gen se_gmean_gr_pop_1995_2018 = (SE_pop_total[119]/SE_pop_total[96])^(1/23) - 1

*** change in the nWIR in pp.
gen se_nWIR_delta_1995_2018 = SE_nWIR_excl_domW_agriW[119]-SE_nWIR_excl_domW_agriW[96]

*** Net national savings rate weighted by national, 1995-2018*****
gen se_sum_saveR_nni = sum(SE_nni_T_R*SE_saveR_n) if year >1994
gen se_sum_nni = sum(SE_nni_T_R) if year >1994
gen se_saveR_n_1995_2018 = se_sum_saveR_nni[119]/se_sum_nni[119]


***** United States *****
*** geometric average growth rate of real national income 
gen us_gmean_gr_nni_1995_2018 = (US_nni_T_R[119]/US_nni_T_R[96])^(1/23) - 1

*** geometric average growth rate of real per capita national income
gen us_gmean_gr_nni_PC_1995_2018 = (US_nni_PC_R[119]/US_nni_PC_R[96])^(1/23) - 1

*** geometric average growth rate of population
gen us_gmean_gr_pop_1995_2018 = (US_pop_total[119]/US_pop_total[96])^(1/23) - 1

*** change in the nWIR in pp.
gen us_nWIR_delta_1995_2018 = US_nWIR_excl_domW_agriW[119]-US_nWIR_excl_domW_agriW[96]

*** Net national savings rate weighted by national, 1995-2018*****
gen us_sum_saveR_nni = sum(US_nni_T_R*US_saveR_n) if year >1994
gen us_sum_nni = sum(US_nni_T_R) if year >1994
gen us_saveR_n_1995_2018 = us_sum_saveR_nni[119]/us_sum_nni[119]


*** export
keep year ch_gmean_gr_nni_1995_2018 ch_gmean_gr_pop_1995_2018 ch_gmean_gr_nni_PC_1995_2018 ch_saveR_n_1995_2018 ch_nWIR_delta_1995_2018 de_gmean_gr_nni_1995_2018 de_gmean_gr_pop_1995_2018 de_gmean_gr_nni_PC_1995_2018 de_saveR_n_1995_2018 de_nWIR_delta_1995_2018 fr_gmean_gr_nni_1995_2018 fr_gmean_gr_pop_1995_2018 fr_gmean_gr_nni_PC_1995_2018 fr_saveR_n_1995_2018 fr_nWIR_delta_1995_2018 it_gmean_gr_nni_1995_2018 it_gmean_gr_pop_1995_2018 it_gmean_gr_nni_PC_1995_2018 it_saveR_n_1995_2018 it_nWIR_delta_1995_2018 se_gmean_gr_nni_1995_2018 se_gmean_gr_pop_1995_2018 se_gmean_gr_nni_PC_1995_2018 se_saveR_n_1995_2018 se_nWIR_delta_1995_2018 us_gmean_gr_nni_1995_2018 us_gmean_gr_pop_1995_2018 us_gmean_gr_nni_PC_1995_2018 us_saveR_n_1995_2018 us_nWIR_delta_1995_2018
drop if year != 2018
drop year
export excel using "Tab_append_B_3.xls", firstrow(variables) replace




*********************************************************************
***** Generate Table B4
*********************************************************************

**********************************************************************
***************  Accumulation of National Wealth 1995-2018 ***********
**********************************************************************
***read data 
cd "$mypath/final_data/"
use "WIR_final.dta", clear
cd "$mypath/output/tables/"



***** Switzerland *****
*** nWIR
gen ch_nWIR_1995 = ch_nWIR_T[96]
gen ch_nWIR_2018 = ch_nWIR_T[119]

*** growth rate of real national wealth
gen ch_nW_gr_T_R = ch_nW_T_R / ch_nW_T_R[_n-1]

*** savings indueced wealth grwoth rate
gen ch_gwst = ch_saveR_n[_n-1] / ch_nWIR_T[_n-1] +1

*** capital-gains-indueced wealth growth rate
gen ch_qt = (ch_nW_gr_T_R)/(ch_gwst)

***1995-2018
gen ch_nW_gr_1995_2018_1 = (ch_nW_T_R[119]/ch_nW_T_R[96])^(1/23) -1
egen ch_nW_gr1_1995_2018 = prod(ch_nW_gr_T_R) if year>=1996 & year<=2018
gen ch_nW_gr_1995_2018 = (ch_nW_gr1_1995_2018)^(1/23) -1
gen dif_test = ch_nW_gr_1995_2018_1 - ch_nW_gr_1995_2018
drop dif_test

egen ch_gwst_gr1_1995_2018 = prod(ch_gwst) if year>=1996 & year<=2018
gen ch_gwst_gr_1995_2018 = (ch_gwst_gr1_1995_2018)^(1/23) -1
egen ch_qt_gr1_1995_2018 = prod(ch_qt) if year>=1996 & year<=2018
gen ch_qt_gr_1995_2018 = (ch_qt_gr1_1995_2018)^(1/23) -1
gen ch_dif_test = ch_nW_gr_1995_2018 - ch_gwst_gr_1995_2018 - ch_qt_gr_1995_2018
drop ch_dif_test



***** Germany *****
*** nWIR
gen de_nWIR_1995 = DE_nWIR_excl_domW_agriW[96]
gen de_nWIR_2018 = DE_nWIR_excl_domW_agriW[119]

*** growth rate of real national wealth
gen de_nni_gr_T_R = DE_nni_T_R / DE_nni_T_R[_n-1] -1 
gen de_nW_T_R = DE_nWIR_excl_domW_agriW * DE_nni_T_R
gen de_nW_gr_T_R = de_nW_T_R / de_nW_T_R[_n-1]
gen de_nW_gr_T_R_2 = (DE_nWIR_excl_domW_agriW/DE_nWIR_excl_domW_agriW[_n-1])*(1+de_nni_gr_T_R)
gen test_dif = de_nW_gr_T_R - de_nW_gr_T_R_2
drop test_dif

*** savings indueced wealth grwoth rate
gen de_gwst = DE_saveR_n[_n-1] / DE_nWIR_excl_domW_agriW[_n-1] +1

*** capital-gains-indueced wealth growth rate
gen de_qt = (de_nW_gr_T_R)/(de_gwst)

***1995-2018
gen de_nW_gr_1995_2018_1 = (DE_nW_T_R[119]/DE_nW_T_R[96])^(1/23) -1
egen de_nW_gr1_1995_2018 = prod(de_nW_gr_T_R) if year>=1996 & year<=2018
gen de_nW_gr_1995_2018 = (de_nW_gr1_1995_2018)^(1/23) -1
gen dif_test = ch_nW_gr_1995_2018_1 - ch_nW_gr_1995_2018
drop dif_test

egen de_gwst_gr1_1995_2018 = prod(de_gwst) if year>=1996 & year<=2018
gen de_gwst_gr_1995_2018 = (de_gwst_gr1_1995_2018)^(1/23) -1
egen de_qt_gr1_1995_2018 = prod(de_qt) if year>=1996 & year<=2018
gen de_qt_gr_1995_2018 = (de_qt_gr1_1995_2018)^(1/23) -1
gen de_dif_test = de_nW_gr_1995_2018 - de_gwst_gr_1995_2018 - de_qt_gr_1995_2018
drop de_dif_test



***** France *****
*** nWIR
gen fr_nWIR_1995 = FR_nWIR_excl_domW_agriW[96]
gen fr_nWIR_2018 = FR_nWIR_excl_domW_agriW[119]

*** growth rate of real national wealth
gen fr_nni_gr_T_R = FR_nni_T_R / FR_nni_T_R[_n-1] -1 
gen fr_nW_T_R = FR_nWIR_excl_domW_agriW * FR_nni_T_R
gen fr_nW_gr_T_R = fr_nW_T_R / fr_nW_T_R[_n-1]
gen fr_nW_gr_T_R_2 = (FR_nWIR_excl_domW_agriW/FR_nWIR_excl_domW_agriW[_n-1])*(1+fr_nni_gr_T_R)
gen test_dif = fr_nW_gr_T_R - fr_nW_gr_T_R_2
drop test_dif

*** savings indueced wealth grwoth rate
gen fr_gwst = FR_saveR_n[_n-1] / FR_nWIR_excl_domW_agriW[_n-1] +1

*** capital-gains-indueced wealth growth rate
gen fr_qt = (fr_nW_gr_T_R)/(fr_gwst)

***1995-2018
gen fr_nW_gr_1995_2018_1 = (FR_nW_T_R[119]/FR_nW_T_R[96])^(1/23) -1
egen fr_nW_gr1_1995_2018 = prod(fr_nW_gr_T_R) if year>=1996 & year<=2018
gen fr_nW_gr_1995_2018 = (fr_nW_gr1_1995_2018)^(1/23) -1
gen dif_test = ch_nW_gr_1995_2018_1 - ch_nW_gr_1995_2018
drop dif_test

egen fr_gwst_gr1_1995_2018 = prod(fr_gwst) if year>=1996 & year<=2018
gen fr_gwst_gr_1995_2018 = (fr_gwst_gr1_1995_2018)^(1/23) -1
egen fr_qt_gr1_1995_2018 = prod(fr_qt) if year>=1996 & year<=2018
gen fr_qt_gr_1995_2018 = (fr_qt_gr1_1995_2018)^(1/23) -1
gen fr_dif_test = fr_nW_gr_1995_2018 - fr_gwst_gr_1995_2018 - fr_qt_gr_1995_2018
drop fr_dif_test



***** Italy *****
*** nWIR
gen it_nWIR_1995 = IT_nWIR_excl_domW_agriW[96]
gen it_nWIR_2018 = IT_nWIR_excl_domW_agriW[118]

*** growth rate of real national wealth
gen it_nni_gr_T_R = IT_nni_T_R / IT_nni_T_R[_n-1] -1 
gen it_nW_T_R = IT_nWIR_excl_domW_agriW * IT_nni_T_R
gen it_nW_gr_T_R = it_nW_T_R / it_nW_T_R[_n-1]
gen it_nW_gr_T_R_2 = (IT_nWIR_excl_domW_agriW/IT_nWIR_excl_domW_agriW[_n-1])*(1+it_nni_gr_T_R)
gen test_dif = it_nW_gr_T_R - it_nW_gr_T_R_2
drop test_dif

*** savings indueced wealth grwoth rate
gen it_gwst = IT_saveR_n[_n-1] / IT_nWIR_excl_domW_agriW[_n-1] +1

*** capital-gains-indueced wealth growth rate
gen it_qt = (it_nW_gr_T_R)/(it_gwst)

***1995-2018
gen it_nW_gr_1995_2018_1 = (IT_nW_T_R[119]/IT_nW_T_R[96])^(1/23) -1
egen it_nW_gr1_1995_2018 = prod(it_nW_gr_T_R) if year>=1996 & year<=2018
gen it_nW_gr_1995_2018 = (it_nW_gr1_1995_2018)^(1/23) -1
gen dif_test = ch_nW_gr_1995_2018_1 - ch_nW_gr_1995_2018
drop dif_test

egen it_gwst_gr1_1995_2018 = prod(it_gwst) if year>=1996 & year<=2018
gen it_gwst_gr_1995_2018 = (it_gwst_gr1_1995_2018)^(1/23) -1
egen it_qt_gr1_1995_2018 = prod(it_qt) if year>=1996 & year<=2018
gen it_qt_gr_1995_2018 = (it_qt_gr1_1995_2018)^(1/23) -1
gen it_dif_test = it_nW_gr_1995_2018 - it_gwst_gr_1995_2018 - it_qt_gr_1995_2018
drop it_dif_test



***** SWEDEN *****
*** nWIR
gen se_nWIR_1995 = SE_nWIR_excl_domW_agriW[96]
gen se_nWIR_2018 = SE_nWIR_excl_domW_agriW[119]

*** growth rate of real national wealth
gen se_nni_gr_T_R = SE_nni_T_R / SE_nni_T_R[_n-1] -1 
gen se_nW_T_R = SE_nWIR_excl_domW_agriW * SE_nni_T_R
gen se_nW_gr_T_R = se_nW_T_R / se_nW_T_R[_n-1]
gen se_nW_gr_T_R_2 = (SE_nWIR_excl_domW_agriW/SE_nWIR_excl_domW_agriW[_n-1])*(1+se_nni_gr_T_R)
gen test_dif = se_nW_gr_T_R - se_nW_gr_T_R_2
drop test_dif

*** savings indueced wealth grwoth rate
gen se_gwst = SE_saveR_n[_n-1] / SE_nWIR_excl_domW_agriW[_n-1] +1

*** capital-gains-indueced wealth growth rate
gen se_qt = (se_nW_gr_T_R)/(se_gwst)

***1995-2018
gen se_nW_gr_1995_2018_1 = (SE_nW_T_R[119]/SE_nW_T_R[96])^(1/23) -1
egen se_nW_gr1_1995_2018 = prod(se_nW_gr_T_R) if year>=1996 & year<=2018
gen se_nW_gr_1995_2018 = (se_nW_gr1_1995_2018)^(1/23) -1
gen dif_test = ch_nW_gr_1995_2018_1 - ch_nW_gr_1995_2018
drop dif_test

egen se_gwst_gr1_1995_2018 = prod(se_gwst) if year>=1996 & year<=2018
gen se_gwst_gr_1995_2018 = (se_gwst_gr1_1995_2018)^(1/23) -1
egen se_qt_gr1_1995_2018 = prod(se_qt) if year>=1996 & year<=2018
gen se_qt_gr_1995_2018 = (se_qt_gr1_1995_2018)^(1/23) -1
gen se_dif_test = se_nW_gr_1995_2018 - se_gwst_gr_1995_2018 - se_qt_gr_1995_2018
drop se_dif_test



***** UNITED STATES *****
*** nWIR
gen us_nWIR_1995 = US_nWIR_excl_domW_agriW[96]
gen us_nWIR_2018 = US_nWIR_excl_domW_agriW[119]

*** growth rate of real national wealth
gen us_nni_gr_T_R = US_nni_T_R / US_nni_T_R[_n-1] -1 
gen us_nW_T_R = US_nWIR_excl_domW_agriW * US_nni_T_R
gen us_nW_gr_T_R = us_nW_T_R / us_nW_T_R[_n-1]
gen us_nW_gr_T_R_2 = (US_nWIR_excl_domW_agriW/US_nWIR_excl_domW_agriW[_n-1])*(1+us_nni_gr_T_R)
gen test_dif = us_nW_gr_T_R - us_nW_gr_T_R_2
drop test_dif

*** savings indueced wealth grwoth rate
gen us_gwst = US_saveR_n[_n-1] / US_nWIR_excl_domW_agriW[_n-1] +1

*** capital-gains-indueced wealth growth rate
gen us_qt = (us_nW_gr_T_R)/(us_gwst)

***1995-2018
gen us_nW_gr_1995_2018_1 = (US_nW_T_R[119]/US_nW_T_R[96])^(1/23) -1
egen us_nW_gr1_1995_2018 = prod(us_nW_gr_T_R) if year>=1996 & year<=2018
gen us_nW_gr_1995_2018 = (us_nW_gr1_1995_2018)^(1/23) -1
gen dif_test = ch_nW_gr_1995_2018_1 - ch_nW_gr_1995_2018
drop dif_test

egen us_gwst_gr1_1995_2018 = prod(us_gwst) if year>=1996 & year<=2018
gen us_gwst_gr_1995_2018 = (us_gwst_gr1_1995_2018)^(1/23) -1
egen us_qt_gr1_1995_2018 = prod(us_qt) if year>=1996 & year<=2018
gen us_qt_gr_1995_2018 = (us_qt_gr1_1995_2018)^(1/23) -1
gen us_dif_test = us_nW_gr_1995_2018 - us_gwst_gr_1995_2018 - us_qt_gr_1995_2018
drop us_dif_test


*** Export
keep year ch_nWIR_1995 ch_nWIR_2018 ch_nW_gr_1995_2018 ch_gwst_gr_1995_2018 ch_qt_gr_1995_2018 de_nWIR_1995 de_nWIR_2018 de_nW_gr_1995_2018 de_gwst_gr_1995_2018 de_qt_gr_1995_2018 fr_nWIR_1995 fr_nWIR_2018 fr_nW_gr_1995_2018 fr_gwst_gr_1995_2018 fr_qt_gr_1995_2018 it_nWIR_1995 it_nWIR_2018 it_nW_gr_1995_2018 it_gwst_gr_1995_2018 it_qt_gr_1995_2018 se_nWIR_1995 se_nWIR_2018 se_nW_gr_1995_2018 se_gwst_gr_1995_2018 se_qt_gr_1995_2018 us_nWIR_1995 us_nWIR_2018 us_nW_gr_1995_2018 us_gwst_gr_1995_2018 us_qt_gr_1995_2018
drop if year != 2018
drop year
export excel using "Tab_append_B_4.xls", firstrow(variables) replace




*********************************************************************
***** Generate Table B5
*********************************************************************

*********************************************************************
*************** Capital Gains - Full-Decomposition, 2000-2020 *******
*********************************************************************
***read data 
cd "$mypath/final_data/"
use "WIR_final.dta", clear
cd "$mypath/output/tables/"


***NWIR Decomposition
*** nWIR
gen ch_nWIR_2000 = ch_nWIR_T[101]
gen ch_nWIR_2010 = ch_nWIR_T[111]
gen ch_nWIR_2020 = ch_nWIR_T[121]

*** growth rate of real national wealth
gen ch_nW_gr_T_R = ch_nW_T_R / ch_nW_T_R[_n-1]
gen ch_nW_gr_T_R_2 = (ch_nWIR_T/ch_nWIR_T[_n-1])*(1+ch_nni_gr_T_R)

*** savings indueced wealth grwoth rate
gen ch_gwst = ch_saveR_n[_n-1] / ch_nWIR_T[_n-1] +1

*** capital-gains-indueced wealth growth rate
gen ch_qt = (ch_nW_gr_T_R)/(ch_gwst)



***2000-2020
gen ch_nW_gr_2000_2020_1 = (ch_nW_T_R[121]/ch_nW_T_R[101])^(1/20) -1
egen ch_nW_gr1_2000_2020 = prod(ch_nW_gr_T_R) if year>=2001 & year<=2020
gen ch_nW_gr_2000_2020 = (ch_nW_gr1_2000_2020)^(1/20) -1
gen dif_test = ch_nW_gr_2000_2020_1 - ch_nW_gr_2000_2020
drop dif_test

egen ch_gwst_gr1_2000_2020 = prod(ch_gwst) if year>=2001 & year<=2020
gen ch_gwst_gr_2000_2020 = (ch_gwst_gr1_2000_2020)^(1/20) -1
egen ch_qt_gr1_2000_2020 = prod(ch_qt) if year>=2001 & year<=2020
gen ch_qt_gr_2000_2020 = (ch_qt_gr1_2000_2020)^(1/20) -1
gen ch_dif1 = ch_nW_gr_2000_2020 - ch_gwst_gr_2000_2020 - ch_qt_gr_2000_2020
drop ch_dif1




***2000-2010
gen ch_nW_gr_2000_2010_1 = (ch_nW_T_R[111]/ch_nW_T_R[101])^(1/10) -1
egen ch_nW_gr1_2000_2010 = prod(ch_nW_gr_T_R) if year>=2001 & year<=2010
gen ch_nW_gr_2000_2010 = (ch_nW_gr1_2000_2010)^(1/10) -1
gen dif_test = ch_nW_gr_2000_2010_1 - ch_nW_gr_2000_2010
drop dif_test

egen ch_gwst_gr1_2000_2010 = prod(ch_gwst) if year>=2001 & year<=2010
gen ch_gwst_gr_2000_2010 = (ch_gwst_gr1_2000_2010)^(1/10) -1
egen ch_qt_gr1_2000_2010 = prod(ch_qt) if year>=2001 & year<=2010
gen ch_qt_gr_2000_2010 = (ch_qt_gr1_2000_2010)^(1/10) -1
gen ch_dif2 = ch_nW_gr_2000_2010 - ch_gwst_gr_2000_2010 - ch_qt_gr_2000_2010
drop ch_dif2



***2010-2020
gen ch_nW_gr_2010_2020_1 = (ch_nW_T_R[121]/ch_nW_T_R[111])^(1/10) -1
egen ch_nW_gr1_2010_2020 = prod(ch_nW_gr_T_R) if year>=2011 & year<=2020
gen ch_nW_gr_2010_2020 = (ch_nW_gr1_2010_2020)^(1/10) -1
gen dif_test = ch_nW_gr_2010_2020_1 - ch_nW_gr_2010_2020
drop dif_test

egen ch_gwst_gr1_2010_2020 = prod(ch_gwst) if year>=2011 & year<=2020
gen ch_gwst_gr_2010_2020 = (ch_gwst_gr1_2010_2020)^(1/10) -1
egen ch_qt_gr1_2010_2020 = prod(ch_qt) if year>=2011 & year<=2020
gen ch_qt_gr_2010_2020 = (ch_qt_gr1_2010_2020)^(1/10) -1
gen ch_dif3 = ch_nW_gr_2010_2020 - ch_gwst_gr_2010_2020 - ch_qt_gr_2010_2020
drop ch_dif3



**********************************************************************************
***GovernmentWIR Decomposition
*** gWIR
gen ch_gWIR_2000 = ch_gWIR_net_staat_cor[101]
gen ch_gWIR_2010 = ch_gWIR_net_staat_cor[111]
gen ch_gWIR_2020 = ch_gWIR_net_staat_cor[121]

*** growth rate of real public wealth
gen ch_gW_net_staat_cor_R = ch_gW_net_staat_cor / ch_cpi
gen ch_gW_gr_cor_R = ch_gW_net_staat_cor_R / ch_gW_net_staat_cor_R[_n-1]
gen ch_gW_gr_cor_R_2 = (ch_gWIR_net_staat_cor/ch_gWIR_net_staat_cor[_n-1])*(1+ch_nni_gr_T_R)

*** savings indueced wealth grwoth rate
gen ch_g_gwst = ch_saveR_g[_n-1] / ch_gWIR_net_staat_cor[_n-1] +1

*** capital-gains-indueced wealth growth rate
gen ch_g_qt = (ch_gW_gr_cor_R)/(ch_g_gwst)


***2000-2020
gen ch_gW_gr_2000_2020_1 = (ch_gW_net_staat_cor_R[121]/ch_gW_net_staat_cor_R[101])^(1/20) -1
egen ch_gW_gr1_2000_2020 = prod(ch_gW_gr_cor_R) if year>=2001 & year<=2020
gen ch_gW_gr_2000_2020 = (ch_gW_gr1_2000_2020)^(1/20) -1
gen dif_test = ch_gW_gr_2000_2020_1 - ch_gW_gr_2000_2020
drop dif_test

egen ch_g_gwst_gr1_2000_2020 = prod(ch_g_gwst) if year>=2001 & year<=2020
gen ch_g_gwst_gr_2000_2020 = (ch_g_gwst_gr1_2000_2020)^(1/20) -1
egen ch_g_qt_gr1_2000_2020 = prod(ch_g_qt) if year>=2001 & year<=2020
gen ch_g_qt_gr_2000_2020 = (ch_g_qt_gr1_2000_2020)^(1/20) -1
gen ch_dif1 = ch_gW_gr_2000_2020 - ch_g_gwst_gr_2000_2020 - ch_g_qt_gr_2000_2020
drop ch_dif1

***2000-2010
gen ch_gW_gr_2000_2010_1 = (ch_gW_net_staat_cor_R[111]/ch_gW_net_staat_cor_R[101])^(1/10) -1
egen ch_gW_gr1_2000_2010 = prod(ch_gW_gr_cor_R) if year>=2001 & year<=2010
gen ch_gW_gr_2000_2010 = (ch_gW_gr1_2000_2010)^(1/10) -1
gen dif_test = ch_gW_gr_2000_2010_1 - ch_gW_gr_2000_2010
drop dif_test

egen ch_g_gwst_gr1_2000_2010 = prod(ch_g_gwst) if year>=2001 & year<=2010
gen ch_g_gwst_gr_2000_2010 = (ch_g_gwst_gr1_2000_2010)^(1/10) -1
egen ch_g_qt_gr1_2000_2010 = prod(ch_g_qt) if year>=2001 & year<=2010
gen ch_g_qt_gr_2000_2010 = (ch_g_qt_gr1_2000_2010)^(1/10) -1
gen ch_dif2 = ch_gW_gr_2000_2010 - ch_g_gwst_gr_2000_2010 - ch_g_qt_gr_2000_2010
drop ch_dif2

***2010-2020///here
gen ch_gW_gr_2010_2020_1 = (ch_gW_net_staat_cor_R[121]/ch_gW_net_staat_cor_R[111])^(1/10) -1
egen ch_gW_gr1_2010_2020 = prod(ch_gW_gr_cor_R) if year>=2011 & year<=2020
gen ch_gW_gr_2010_2020 = (ch_gW_gr1_2010_2020)^(1/10) -1
gen dif_test = ch_gW_gr_2010_2020_1 - ch_gW_gr_2010_2020
drop dif_test

egen ch_g_gwst_gr1_2010_2020 = prod(ch_g_gwst) if year>=2011 & year<=2020
gen ch_g_gwst_gr_2010_2020 = (ch_g_gwst_gr1_2010_2020)^(1/10) -1
egen ch_g_qt_gr1_2010_2020 = prod(ch_g_qt) if year>=2011 & year<=2020
gen ch_g_qt_gr_2010_2020 = (ch_g_qt_gr1_2010_2020)^(1/10) -1
gen ch_dif3 = ch_gW_gr_2010_2020 - ch_g_gwst_gr_2010_2020 - ch_g_qt_gr_2010_2020
drop ch_dif3


**********************************************************************************
***PrivateWIR Decomposition
*** pWIR
gen ch_pWIR_2000 = ch_pWIR[101]
gen ch_pWIR_2010 = ch_pWIR[111]
gen ch_pWIR_2020 = ch_pWIR[121]

*** growth rate of real private wealth
gen ch_pW_gr_T_R = ch_pW_T_R / ch_pW_T_R[_n-1]
gen ch_pW_gr_T_R_2 = (ch_pWIR/ch_pWIR[_n-1])*(1+ch_nni_gr_T_R)


*** savings indueced wealth grwoth rate
gen ch_p_gwst = ch_saveR_HH_nP[_n-1] / ch_pWIR[_n-1] +1

*** capital-gains-indueced wealth growth rate
gen ch_p_qt = (ch_pW_gr_T_R)/(ch_p_gwst)





***2000-2020
gen ch_pW_gr_2000_2020_1 = (ch_pW_T_R[121]/ch_pW_T_R[101])^(1/20) -1
egen ch_pW_gr1_2000_2020 = prod(ch_pW_gr_T_R) if year>=2001 & year<=2020
gen ch_pW_gr_2000_2020 = (ch_pW_gr1_2000_2020)^(1/20) -1
gen dif_test = ch_pW_gr_2000_2020_1 - ch_pW_gr_2000_2020
drop dif_test

egen ch_p_gwst_gr1_2000_2020 = prod(ch_p_gwst) if year>=2001 & year<=2020
gen ch_p_gwst_gr_2000_2020 = (ch_p_gwst_gr1_2000_2020)^(1/20) -1
egen ch_p_qt_gr1_2000_2020 = prod(ch_p_qt) if year>=2001 & year<=2020
gen ch_p_qt_gr_2000_2020 = (ch_p_qt_gr1_2000_2020)^(1/20) -1
gen ch_dif1 = ch_pW_gr_2000_2020 - ch_p_gwst_gr_2000_2020 - ch_p_qt_gr_2000_2020
drop ch_dif1

***2000-2010
gen ch_pW_gr_2000_2010_1 = (ch_pW_T_R[111]/ch_pW_T_R[101])^(1/10) -1
egen ch_pW_gr1_2000_2010 = prod(ch_pW_gr_T_R) if year>=2001 & year<=2010
gen ch_pW_gr_2000_2010 = (ch_pW_gr1_2000_2010)^(1/10) -1
gen dif_test = ch_pW_gr_2000_2010_1 - ch_pW_gr_2000_2010
drop dif_test

egen ch_p_gwst_gr1_2000_2010 = prod(ch_p_gwst) if year>=2001 & year<=2010
gen ch_p_gwst_gr_2000_2010 = (ch_p_gwst_gr1_2000_2010)^(1/10) -1
egen ch_p_qt_gr1_2000_2010 = prod(ch_p_qt) if year>=2001 & year<=2010
gen ch_p_qt_gr_2000_2010 = (ch_p_qt_gr1_2000_2010)^(1/10) -1
gen ch_dif2 = ch_pW_gr_2000_2010 - ch_p_gwst_gr_2000_2010 - ch_p_qt_gr_2000_2010
drop ch_dif2

***2010-2020
gen ch_pW_gr_2010_2020_1 = (ch_pW_T_R[121]/ch_pW_T_R[111])^(1/10) -1
egen ch_pW_gr1_2010_2020 = prod(ch_pW_gr_T_R) if year>=2011 & year<=2020
gen ch_pW_gr_2010_2020 = (ch_pW_gr1_2010_2020)^(1/10) -1
gen dif_test = ch_pW_gr_2010_2020_1 - ch_pW_gr_2010_2020
drop dif_test

egen ch_p_gwst_gr1_2010_2020 = prod(ch_p_gwst) if year>=2011 & year<=2020
gen ch_p_gwst_gr_2010_2020 = (ch_p_gwst_gr1_2010_2020)^(1/10) -1
egen ch_p_qt_gr1_2010_2020 = prod(ch_p_qt) if year>=2011 & year<=2020
gen ch_p_qt_gr_2010_2020 = (ch_p_qt_gr1_2010_2020)^(1/10) -1
gen ch_dif3 = ch_pW_gr_2010_2020 - ch_p_gwst_gr_2010_2020 - ch_p_qt_gr_2010_2020
drop ch_dif3


*** Export
keep year ch_nWIR_2000 ch_nWIR_2010 ch_nWIR_2020 ch_gWIR_2000 ch_gWIR_2010 ch_gWIR_2020 ch_pWIR_2000 ch_pWIR_2010 ch_pWIR_2020 ch_nW_gr_2000_2020 ch_gwst_gr_2000_2020 ch_qt_gr_2000_2020 ch_nW_gr_2000_2010 ch_gwst_gr_2000_2010 ch_qt_gr_2000_2010 ch_nW_gr_2010_2020 ch_gwst_gr_2010_2020 ch_qt_gr_2010_2020 ch_gW_gr_2000_2020 ch_g_gwst_gr_2000_2020 ch_g_qt_gr_2000_2020 ch_gW_gr_2000_2010 ch_g_gwst_gr_2000_2010 ch_g_qt_gr_2000_2010 ch_gW_gr_2010_2020 ch_g_gwst_gr_2010_2020 ch_g_qt_gr_2010_2020 ch_pW_gr_2000_2020 ch_p_gwst_gr_2000_2020 ch_p_qt_gr_2000_2020 ch_pW_gr_2000_2010 ch_p_gwst_gr_2000_2010 ch_p_qt_gr_2000_2010 ch_pW_gr_2010_2020 ch_p_gwst_gr_2010_2020 ch_p_qt_gr_2010_2020

replace ch_nW_gr_2000_2010 = ch_nW_gr_2000_2010[107]
replace ch_gwst_gr_2000_2010 = ch_gwst_gr_2000_2010[107] 
replace ch_qt_gr_2000_2010 = ch_qt_gr_2000_2010[107]
replace ch_gW_gr_2000_2010 = ch_gW_gr_2000_2010[107]
replace ch_g_gwst_gr_2000_2010 = ch_g_gwst_gr_2000_2010[107] 
replace ch_g_qt_gr_2000_2010 = ch_g_qt_gr_2000_2010[107]
replace ch_pW_gr_2000_2010 = ch_pW_gr_2000_2010[107]
replace ch_p_gwst_gr_2000_2010 = ch_p_gwst_gr_2000_2010[107] 
replace ch_p_qt_gr_2000_2010 = ch_p_qt_gr_2000_2010[107]

drop if year != 2020
drop year
export excel using "Tab_append_B_5.xls", firstrow(variables)

******







*********************************************************************
***** Generate Table B6
*********************************************************************

************************************************************************
****************** Private WIR Decomposition ***************************
****************** Housing vs Non-housing    ***************************
************************************************************************
*** Private savings including retained earnings of corporations 

***read data 
cd "$mypath/final_data/"
use "WIR_final.dta", clear
cd "$mypath/output/tables/"


***PrivateWIR Decomposition
*** pWIR
gen ch_pWIR_2000 = ch_pWIR[101]
gen ch_pWIR_2010 = ch_pWIR[111]
gen ch_pWIR_2020 = ch_pWIR[121]

*** growth rate of real private wealth
gen ch_pW_gr_T_R = ch_pW_T_R / ch_pW_T_R[_n-1]

*** savings indueced wealth grwoth rate
gen ch_p_gwst = ch_saveR_p[_n-1] / ch_pWIR[_n-1] +1

*** capital-gains-indueced wealth growth rate
gen ch_p_qt = (ch_pW_gr_T_R)/(ch_p_gwst)


***2000-2020
egen ch_pW_gr1_2000_2020 = prod(ch_pW_gr_T_R) if year>=2001 & year<=2020
gen ch_pW_gr_2000_2020 = (ch_pW_gr1_2000_2020)^(1/20) -1
egen ch_p_gwst_gr1_2000_2020 = prod(ch_p_gwst) if year>=2001 & year<=2020
gen ch_p_gwst_gr_2000_2020 = (ch_p_gwst_gr1_2000_2020)^(1/20) -1
egen ch_p_qt_gr1_2000_2020 = prod(ch_p_qt) if year>=2001 & year<=2020
gen ch_p_qt_gr_2000_2020 = (ch_p_qt_gr1_2000_2020)^(1/20) -1
gen ch_dif1 = ch_pW_gr_2000_2020 - ch_p_gwst_gr_2000_2020 - ch_p_qt_gr_2000_2020
drop ch_dif1

***2000-2010
egen ch_pW_gr1_2000_2010 = prod(ch_pW_gr_T_R) if year>=2001 & year<=2010
gen ch_pW_gr_2000_2010 = (ch_pW_gr1_2000_2010)^(1/10) -1
egen ch_p_gwst_gr1_2000_2010 = prod(ch_p_gwst) if year>=2001 & year<=2010
gen ch_p_gwst_gr_2000_2010 = (ch_p_gwst_gr1_2000_2010)^(1/10) -1
egen ch_p_qt_gr1_2000_2010 = prod(ch_p_qt) if year>=2001 & year<=2010
gen ch_p_qt_gr_2000_2010 = (ch_p_qt_gr1_2000_2010)^(1/10) -1
gen ch_dif2 = ch_pW_gr_2000_2010 - ch_p_gwst_gr_2000_2010 - ch_p_qt_gr_2000_2010
drop ch_dif2

***2010-2020
egen ch_pW_gr1_2010_2020 = prod(ch_pW_gr_T_R) if year>=2011 & year<=2020
gen ch_pW_gr_2010_2020 = (ch_pW_gr1_2010_2020)^(1/10) -1
egen ch_p_gwst_gr1_2010_2020 = prod(ch_p_gwst) if year>=2011 & year<=2020
gen ch_p_gwst_gr_2010_2020 = (ch_p_gwst_gr1_2010_2020)^(1/10) -1
egen ch_p_qt_gr1_2010_2020 = prod(ch_p_qt) if year>=2011 & year<=2020
gen ch_p_qt_gr_2010_2020 = (ch_p_qt_gr1_2010_2020)^(1/10) -1
gen ch_dif3 = ch_pW_gr_2010_2020 - ch_p_gwst_gr_2010_2020 - ch_p_qt_gr_2010_2020
drop ch_dif3





****nominal changens in net private wealth -- are used for further computations below
/// change in net private Wealth from year to year nominal
gen ch_pW_T_yearly_change = ch_pW_T - ch_pW_T[_n-1] if year >= 2000
/// savings indueced change in net private Wealth from year to year
gen ch_pW_save_yearly_change = ch_saveR_p * ch_nni_T if year >= 2000
/// capitalgains indueced change in net private Wealth from year to year / can be estimated as residual 
gen ch_pW_cpg_yearly_change = ch_pW_T_yearly_change - ch_pW_save_yearly_change




**************************************************************************************************
******************* Decomposition of Housing and non Housing Private Wealth***********************
**************************************************************************************************

**** Non-housing-Wealth*** --> Net Financial Wealth including Pension wealth

***Non-Housing-WIR 
gen ch_nonHouseWIR = (ch_pW_netfin_T+ch_pW_pension_T) / ch_nni_T


gen ch_nonHouseWIR_2000 = ch_nonHouseWIR[101]
gen ch_nonHouseWIR_2010 = ch_nonHouseWIR[111]
gen ch_nonHouseWIR_2020 = ch_nonHouseWIR[121]

*** growth rate of real non-housing wealth
gen ch_pW_nonHouse_T_R = ch_pW_netfin_total_T / ch_cpi
gen ch_pW_nonHouse_gr_T_R = ch_pW_nonHouse_T_R / ch_pW_nonHouse_T_R[_n-1]


*** savings rate of non-housing wealth 
/// from the financial accounts we have additional information on private non-housing Wealth (net financial wealth including pension wealth)
/// we know which part of change in the in non-housing Wealth can be attributed to savings "ch_pW_netfin_total_trans" 
/// capital gains "ch_pW_netfin_total_cp" and statistical changes/reclassifications "ch_pW_netfin_total_statchange"
/// statiscial change are of relevant magnitued and can not just somehow be split up between savings and capital gains 
/// we know however that the major part of statistical changes in non-housing wealth (including pension wealth) comes from reclassifications
/// regarding pension wealth "ch_pW_pension_statchange". These changes are done because considerable part of retirees move abroad and take their pension wealth with
/// them. For our analysis we thus can regard the as negative savings (as these are outflows) since we are intrested in the evolution of wealth of Swiss residents (inländerprinzip)
gen ch_pW_netfin_statchange_rest = ch_pW_netfin_total_statchange - ch_pW_pension_statchange
gen ch_pW_netfin_cpg_fin = ch_pW_netfin_total_cp + ch_pW_netfin_statchange_rest
/// we thus add "ch_pW_pension_statchange" to the savings component to account for the outflow of pension wealth 
/// the rest of statistical reclassifications "ch_pW_netfin_statchange_rest" is add to the capital gains component
gen ch_pW_netfin_save_fin = ch_pW_netfin_total_trans + ch_pW_pension_statchange
gen ch_saveR_nonHouse = ch_pW_netfin_save_fin / ch_nni_T

/// test to see if capital gains in nominal term are derived correctly
gen ch_test_cp = ch_pW_netfin_total_T - ch_pW_netfin_total_T[_n-1] - ch_pW_netfin_save_fin
gen ch_test_cp1 = ch_test_cp - ch_pW_netfin_cpg_fin
drop ch_test_cp ch_test_cp1

*** savings indueced wealth grwoth rate on non-housing wealth
gen ch_nonHouse_gwst = ch_saveR_nonHouse[_n-1] / ch_nonHouseWIR[_n-1] +1

*** capital-gains-indueced wealth growth rate
gen ch_nonHouse_qt = (ch_pW_nonHouse_gr_T_R)/(ch_nonHouse_gwst)



**** Housing-Wealth***
/// total nominal savings in housing are the difference of total household savings and savings in non-housing wealth
gen ch_pW_housing_save = ch_pW_save_yearly_change - ch_pW_netfin_save_fin

/// total nominal capital gains in housing are the difference of total household capital gains and capital gains in non-housing wealth
gen ch_pW_housing_cp = ch_pW_cpg_yearly_change - ch_pW_netfin_cpg_fin

/// change in nominal housing wealth 
gen ch_pW_housing_T_yearly_change = ch_pW_housing_cp + ch_pW_housing_save
gen housing_test = ch_pW_housing_T_yearly_change - (ch_pW_housing_T -ch_pW_housing_T[_n-1])
drop housing_test
/// note that by construction this changes "ch_pW_housing_T_yearly_change" coincidence to the year to year changes of the variable "ch_pW_housing_T"
/// based on the series "ch_pW_housing_T_yearly_change" we further can prolong the series "ch_pW_housing_T" on more period backward (useful to analysis the entire period since 2000)
replace ch_pW_housing_T = ch_pW_housing_T[101] - ch_pW_housing_T_yearly_change[101] if year==1999


***Housing-WIR 
gen ch_HouseWIR = ch_pW_housing_T / ch_nni_T

gen ch_HouseWIR_2000 = ch_HouseWIR[101]
gen ch_HouseWIR_2010 = ch_HouseWIR[111]
gen ch_HouseWIR_2020 = ch_HouseWIR[121]

*** growth rate of real non-housing wealth
drop ch_pW_housing_T_R
gen ch_pW_housing_T_R = ch_pW_housing_T / ch_cpi
gen ch_pW_housing_gr_T_R = ch_pW_housing_T_R / ch_pW_housing_T_R[_n-1]


*** savings indueced wealth grwoth rate on non-housing wealth
gen ch_saveR_housing = ch_pW_housing_save / ch_nni_T
gen ch_housing_gwst = ch_saveR_housing[_n-1] / ch_HouseWIR[_n-1] +1


*** capital-gains-indueced wealth growth rate
gen ch_housing_qt = (ch_pW_housing_gr_T_R)/(ch_housing_gwst)


********************* Non-Housing Decomposition *********************

***2000-2020
egen ch_NonhousW_gr1_2000_2020 = prod(ch_pW_nonHouse_gr_T_R) if year>=2001 & year<=2020
gen ch_NonhousW_gr_2000_2020 = (ch_NonhousW_gr1_2000_2020)^(1/20) -1
egen ch_NonhousW_gwst_gr1_2000_2020 = prod(ch_nonHouse_gwst) if year>=2001 & year<=2020
gen ch_NonhousW_gwst_gr_2000_2020 = (ch_NonhousW_gwst_gr1_2000_2020)^(1/20) -1
egen ch_NonhousW_qt_gr1_2000_2020 = prod(ch_nonHouse_qt) if year>=2001 & year<=2020
gen ch_NonhousW_qt_gr_2000_2020 = (ch_NonhousW_qt_gr1_2000_2020)^(1/20) -1
gen ch_dif1 = ch_NonhousW_gr_2000_2020 - ch_NonhousW_gwst_gr_2000_2020 - ch_NonhousW_qt_gr_2000_2020
drop ch_dif1


***2000-2010
egen ch_NonhousW_gr1_2000_2010 = prod(ch_pW_nonHouse_gr_T_R) if year>=2001 & year<=2010
gen ch_NonhousW_gr_2000_2010 = (ch_NonhousW_gr1_2000_2010)^(1/10) -1
egen ch_NonhousW_gwst_gr1_2000_2010 = prod(ch_nonHouse_gwst) if year>=2001 & year<=2010
gen ch_NonhousW_gwst_gr_2000_2010 = (ch_NonhousW_gwst_gr1_2000_2010)^(1/10) -1
egen ch_NonhousW_qt_gr1_2000_2010 = prod(ch_nonHouse_qt) if year>=2001 & year<=2010
gen ch_NonhousW_qt_gr_2000_2010 = (ch_NonhousW_qt_gr1_2000_2010)^(1/10) -1
gen ch_dif2 = ch_NonhousW_gr_2000_2010 - ch_NonhousW_gwst_gr_2000_2010 - ch_NonhousW_qt_gr_2000_2010
drop ch_dif2

***2010-2020
egen ch_NonhousW_gr1_2010_2020 = prod(ch_pW_nonHouse_gr_T_R) if year>=2011 & year<=2020
gen ch_NonhousW_gr_2010_2020 = (ch_NonhousW_gr1_2010_2020)^(1/10) -1
egen ch_NonhousW_gwst_gr1_2010_2020 = prod(ch_nonHouse_gwst) if year>=2011 & year<=2020
gen ch_NonhousW_gwst_gr_2010_2020 = (ch_NonhousW_gwst_gr1_2010_2020)^(1/10) -1
egen ch_NonhousW_qt_gr1_2010_2020 = prod(ch_nonHouse_qt) if year>=2011 & year<=2020
gen ch_NonhousW_qt_gr_2010_2020 = (ch_NonhousW_qt_gr1_2010_2020)^(1/10) -1
gen ch_dif3 = ch_NonhousW_gr_2010_2020 - ch_NonhousW_gwst_gr_2010_2020 - ch_NonhousW_qt_gr_2010_2020
drop ch_dif3




********************* Housing Decomposition *********************

***2000-2020
egen ch_housingW_gr1_2000_2020 = prod(ch_pW_housing_gr_T_R) if year>=2001 & year<=2020
gen ch_housingW_gr_2000_2020 = (ch_housingW_gr1_2000_2020)^(1/20) -1
egen ch_housing_gwst_gr1_2000_2020 = prod(ch_housing_gwst) if year>=2001 & year<=2020
gen ch_housing_gwst_gr_2000_2020 = (ch_housing_gwst_gr1_2000_2020)^(1/20) -1
egen ch_housing_qt_gr1_2000_2020 = prod(ch_housing_qt) if year>=2001 & year<=2020
gen ch_housing_qt_gr_2000_2020 = (ch_housing_qt_gr1_2000_2020)^(1/20) -1
gen ch_dif1 = ch_housingW_gr_2000_2020 - ch_housing_gwst_gr_2000_2020 - ch_housing_qt_gr_2000_2020
drop ch_dif1

***2000-2010
egen ch_housingW_gr1_2000_2010 = prod(ch_pW_housing_gr_T_R) if year>=2001 & year<=2010
gen ch_housingW_gr_2000_2010 = (ch_housingW_gr1_2000_2010)^(1/10) -1
egen ch_housing_gwst_gr1_2000_2010 = prod(ch_housing_gwst) if year>=2001 & year<=2010
gen ch_housing_gwst_gr_2000_2010 = (ch_housing_gwst_gr1_2000_2010)^(1/10) -1
egen ch_housing_qt_gr1_2000_2010 = prod(ch_housing_qt) if year>=2001 & year<=2010
gen ch_housing_qt_gr_2000_2010 = (ch_housing_qt_gr1_2000_2010)^(1/10) -1
gen ch_dif2 = ch_housingW_gr_2000_2010 - ch_housing_gwst_gr_2000_2010 - ch_housing_qt_gr_2000_2010
drop ch_dif2

***2010-2020
egen ch_housingW_gr1_2010_2020 = prod(ch_pW_housing_gr_T_R) if year>=2011 & year<=2020
gen ch_housingW_gr_2010_2020 = (ch_housingW_gr1_2010_2020)^(1/10) -1
egen ch_housing_gwst_gr1_2010_2020 = prod(ch_housing_gwst) if year>=2011 & year<=2020
gen ch_housing_gwst_gr_2010_2020 = (ch_housing_gwst_gr1_2010_2020)^(1/10) -1
egen ch_housing_qt_gr1_2010_2020 = prod(ch_housing_qt) if year>=2011 & year<=2020
gen ch_housing_qt_gr_2010_2020 = (ch_housing_qt_gr1_2010_2020)^(1/10) -1
gen ch_dif3 = ch_housingW_gr_2010_2020 - ch_housing_gwst_gr_2010_2020 - ch_housing_qt_gr_2010_2020
drop ch_dif3


*** Export
keep year ch_pWIR_2000 ch_pWIR_2010 ch_pWIR_2020 ch_pW_gr_2000_2020 ch_p_gwst_gr_2000_2020 ch_p_qt_gr_2000_2020 ch_pW_gr_2000_2010 ch_p_gwst_gr_2000_2010 ch_p_qt_gr_2000_2010 ch_pW_gr_2010_2020 ch_p_gwst_gr_2010_2020 ch_p_qt_gr_2010_2020 ch_HouseWIR_2000 ch_HouseWIR_2010 ch_HouseWIR_2020 ch_housingW_gr_2000_2020 ch_housing_gwst_gr_2000_2020 ch_housing_qt_gr_2000_2020 ch_housingW_gr_2000_2010 ch_housing_gwst_gr_2000_2010 ch_housing_qt_gr_2000_2010 ch_housingW_gr_2010_2020 ch_housing_gwst_gr_2010_2020 ch_housing_qt_gr_2010_2020 ch_nonHouseWIR_2000 ch_nonHouseWIR_2010 ch_nonHouseWIR_2020 ch_NonhousW_gr_2000_2020 ch_NonhousW_gwst_gr_2000_2020 ch_NonhousW_qt_gr_2000_2020 ch_NonhousW_gr_2000_2010 ch_NonhousW_gwst_gr_2000_2010 ch_NonhousW_qt_gr_2000_2010 ch_NonhousW_gr_2010_2020 ch_NonhousW_gwst_gr_2010_2020 ch_NonhousW_qt_gr_2010_2020

replace ch_pW_gr_2010_2020 = ch_pW_gr_2010_2020[121]
replace ch_p_gwst_gr_2010_2020 = ch_p_gwst_gr_2010_2020[121]
replace ch_p_qt_gr_2010_2020 = ch_p_qt_gr_2010_2020[121]
replace ch_housingW_gr_2010_2020 = ch_housingW_gr_2010_2020[121]
replace ch_housing_gwst_gr_2010_2020 = ch_housing_gwst_gr_2010_2020[121]
replace ch_housing_qt_gr_2010_2020 = ch_housing_qt_gr_2010_2020[121]
replace ch_NonhousW_gr_2010_2020 = ch_NonhousW_gr_2010_2020[121]
replace ch_NonhousW_gwst_gr_2010_2020 = ch_NonhousW_gwst_gr_2010_2020[121]
replace ch_NonhousW_qt_gr_2010_2020 = ch_NonhousW_qt_gr_2010_2020[121]
drop if year != 2010
drop year
export excel using "Tab_append_B_6.xls", firstrow(variables)



**********************************************************************************
***************   GovernmentWIR Decomposition 1995-2020 /Section 6.2 *************
**********************************************************************************

***read data 
cd "$mypath/final_data/"
use "WIR_final.dta", clear
cd "$mypath/output/tables/"


*** gWIR
gen ch_gWIR_1995 = ch_gWIR_net_staat_cor[96]
gen ch_gWIR_2020 = ch_gWIR_net_staat_cor[121]

*** growth rate of real public wealth
gen ch_gW_net_staat_cor_R = ch_gW_net_staat_cor / ch_cpi
gen ch_gW_gr_cor_R = ch_gW_net_staat_cor_R / ch_gW_net_staat_cor_R[_n-1]
gen ch_gW_gr_cor_R_2 = (ch_gWIR_net_staat_cor/ch_gWIR_net_staat_cor[_n-1])*(1+ch_nni_gr_T_R)
gen test_dif = ch_gW_gr_cor_R - ch_gW_gr_cor_R_2
drop test_dif

*** savings indueced wealth grwoth rate
gen ch_g_gwst = ch_saveR_g[_n-1] / ch_gWIR_net_staat_cor[_n-1] +1

*** capital-gains-indueced wealth growth rate
gen ch_g_qt = (ch_gW_gr_cor_R)/(ch_g_gwst)


***1995-2018
gen ch_gW_gr_1995_2020_1 = (ch_gW_net_staat_cor_R[121]/ch_gW_net_staat_cor_R[96])^(1/25) -1
egen ch_gW_gr1_1995_2020 = prod(ch_gW_gr_cor_R) if year>=1996 & year<=2018
gen ch_gW_gr_1995_2020 = (ch_gW_gr1_1995_2020)^(1/25) -1
gen dif_test = ch_gW_gr_1995_2020_1 - ch_gW_gr_1995_2020
drop dif_test

egen ch_g_gwst_gr1_1995_2020 = prod(ch_g_gwst) if year>=1996 & year<=2018
gen ch_g_gwst_gr_1995_2020 = (ch_g_gwst_gr1_1995_2020)^(1/25) -1
egen ch_g_qt_gr1_1995_2020 = prod(ch_g_qt) if year>=1996 & year<=2018
gen ch_g_qt_gr_1995_2020 = (ch_g_qt_gr1_1995_2020)^(1/25) -1
gen ch_dif1 = ch_gW_gr_1995_2020 - ch_g_gwst_gr_1995_2020 - ch_g_qt_gr_1995_2020
drop ch_dif1


cd "$mypath/"
clear all
